<?php
define('THIS_SCRIPT', 'viewinfo');
require_once 'global.php';
$lang = load_lang($lang, 'viewinfo');

define('USER_ID', $userid);
define('MEMBER_NAME', $membername);
define('BOARD_ID', $boardid);
define('TABLE_PREFIX', $dv);
define('NOW_POST_TABLE', $nowtablename);

$action = strtolower(trim($action));

switch($t){
	case '1':
		ViewVoters_Main();
		break;
	case '2':
		ViewTopicInfo_Main();
		break;
	default:
		ViewPaper_Main();
		break;
}

function ViewPaper_Main()	//	查看小字报
{
	global $db, $lang, $stats, $id;
	$stats = $lang['tpl.str11'];
	head();
	if ($id <= 0) {	//	非法的帖子参数！
		showmsg($lang['err.str1']);
		exit;
	} else {
		$pagerid = $id + 0;
	}
	$pagerinfo = false;
	if ($query = $db->query("SELECT s_id,s_boardid,s_username,s_title,s_content,s_hits,s_addtime FROM ".TABLE_PREFIX."smallpaper WHERE s_id='{$pagerid}'")) {
		$pagerinfo =& $db->fetch_array($query);
	}
	if (false === $pagerinfo) {	//	您查找的数据暂不存在！
		showmsg($lang['err.str3']);
		exit;
	}
	//更新点击率
		$db->query("UPDATE ".TABLE_PREFIX."smallpaper SET s_hits=s_hits+1 WHERE s_id='{$pagerid}'");
	require_once INC_PATH.'dv_code.php';
	$crtuserinfo = array('usergroupid'=>4);
	$pagerinfo['s_content'] =& Dv_CodeProcess($pagerinfo['s_content'], $crtuserinfo, '', 2, 1);
	require_once printout('viewinfo');
	footer(false);
}//end function ViewPaper_Main

function ViewVoters_Main()	//	查看投票用户
{
	global $db, $id, $lang, $t, $istoptable;
	$stats = $lang['headtitle'];
	$istoptable = 0;
	head();
	if ( $id == '' || !is_numeric($id) ){	//	非法的帖子参数！
		echo $lang['err.str1'];
		exit;
	}
	$query=$db->query("SELECT vote FROM ".TABLE_PREFIX."vote WHERE voteid=$id");
	if ($vs = $db->fetch_array($query)){
		$votevalue = explode('|',$vs['vote']);
	}else{
		echo $lang['err.str2'];
		exit;
	}
	$query=$db->query("SELECT title,topicmode FROM ".TABLE_PREFIX."topic WHERE pollid=$id");
	if ($ts = $db->fetch_array($query)){
		$title = ChkBadWords($ts['title']);
		//$title = htmlspecialchars(ChkBadWords($ts['title']));
	}else{
		echo $lang['err.str2'];
		exit;
	}
	$istoptable = 0;
	$query=$db->query("SELECT v.*,u.username FROM ".TABLE_PREFIX."voteuser v INNER JOIN ".TABLE_PREFIX."user u ON v.userid=u.userid WHERE voteid=$id");
	require_once printout('viewinfo');
	footer(false);
}//end function ViewVoters_Main

function ViewTopicInfo_Main()	//	查看被赠送金币的用户
{
	global $db, $lang, $groupsetting, $action, $stats, $t, $id, $replyid;
	define('ROOT_ID', (($id > 0) ? $id : 0));
	define('REPLY_ID', (($replyid > 0) ? $replyid : 0));
	if ('view' == $action) {
		$stats = $lang['tpl.str4'];
	} else {
		$stats = $lang['tpl.str5'];
	}
	head();
	if (ROOT_ID <= 0) {	//	非法的帖子参数！
		showmsg($lang['err.str1']);
		exit;
	}
	if ($groupsetting[2] != 1) {	//	您没有浏览在本论坛查看其他人发布的帖子的权限，请<a href="login.php">登录</a>或者同管理员联系。
		showmsg($lang['err.str2']);
		exit;
	}
	$topicinfo =& GetTopicInfo();
	if ($topicinfo['topicmode'] != 1) {
		$topicinfo['title'] = htmlspecialchars($topicinfo['title']);
	}
	require_once printout('viewinfo');
	footer(false);
}//end function ViewTopicInfo_Main

function _getPostTable()
{
	global $lang;
	$topicinfo =& GetTopicInfo();
	return $topicinfo['posttable'];
}//end function _getPostTable

function &GetTopicInfo()
{
	global $lang;
	static $topicinfo;
	if (!isset($topicinfo)) {
		global $db, $lang;
		$topicinfo = false;
		$rs =& $db->getResultSet("SELECT title, postusername, postuserid, dateandtime, child, hits, lastpost, lastposttime, posttable, getmoney, usetools, getmoneytype, topicmode, hidename FROM ".TABLE_PREFIX."topic WHERE topicid='".ROOT_ID."' AND boardid='".BOARD_ID."'", array('pageSize'=>1));
		if (false !== $rs) {
			$topicinfo = $rs[0];
		}
	}
	return $topicinfo;
}//end function GetTopicInfo

function &GetBBsInfo()
{
	global $lang;
	static $bbsinfo;
	if (!isset($bbsinfo)) {
		global $db, $lang;
		$bbsinfo = false;
		$topicinfo =& GetTopicInfo();
		$rs =& $db->getResultSet("SELECT isagree, postbuyuser, getmoney, usetools, getmoneytype, announceid FROM ".$db->escape_string($topicinfo['posttable'])." WHERE rootid='".ROOT_ID."' AND parentid=0 AND boardid='".BOARD_ID."' and forumtype=0", array('pageSize'=>1));
		if (false !== $rs) {
			$bbsinfo = $rs[0];
		} else {
			showmsg($lang['err.str3']);
			exit;
		}
	}
	return $bbsinfo;
}//end function GetBBsInfo

function GetBBsReplyInfo()
{
	global $lang;
	static $replyinfo, $lang;
	if (!isset($replyinfo)) {
		global $db;
		$replyinfo = false;
		$topicinfo =& GetTopicInfo();
		$rs =& $db->getResultSet("SELECT username, postuserid, dateandtime, isagree, postbuyuser, getmoney, usetools, getmoneytype, signflag FROM ".$db->escape_string($topicinfo['posttable'])." WHERE announceid='".REPLY_ID."'", array('pageSize'=>1));
		if (false !== $rs) {
			$replyinfo = $rs[0];
		} else {
			showmsg($lang['err.str3']);
			exit;
		}
	}
	return $replyinfo;
}//end function GetBBsReplyInfo

function GetTopicToolsInfo($toolsid)
{
	global $db, $lang;
	$returnval = $lang['tpl.str10'];
	if (!is_numeric(str_replace(',', '', $toolsid)) OR $toolsid <= 0) {
		return $returnval;
	}
	if (-1111 == $toolsid) {
		return $returnval;
	}
	static $toolsinfo;
	if (!isset($toolsinfo) OR !isset($toolsinfo[$toolsid])) {
		$toolsinfo[$toolsid] = '';
		$tempstr = '';
		if ($query = "SELECT toolsname FROM ".TABLE_PREFIX."plus_tools_info WHERE id IN({$toolsid})") {
			$RowDelimiter = '';
			while ($dbinfo =& $db->fetch_array($query)) {
				$tempstr .= $RowDelimiter;
				$RowDelimiter = '&nbsp;&nbsp;&nbsp;&nbsp;';
				$columnDelimiter = '';
				foreach ($dbinfo AS $val) {
					if (is_null($val)) {
						$val = ' </u>'.$lang['tpl.str41'].'<u> ';
					}
					$tempstr .= $columnDelimiter.$val;
					$columnDelimiter = $lang['tpl.str42'];
				}//end foreach
			}//end while
		}
		$toolsinfo[$toolsid] = $tempstr;
	}
	return $toolsinfo[$toolsid];
}//end function GetTopicToolsInfo

?>