<?php
if( !defined('ISDVBBS') ){
	header('HTTP/1.0 404 Not Found');
	exit;
}
global $t, $fsetting;
if (1 == $t) {
	print <<<EOT
	<table cellpadding="0" cellspacing="0" align="center" class="mainbox tableborder">
	<tr>
	<th colspan="2">{$title}</th>
	</tr>
	<tr align="center">
	<td><b>{$lang['tpl.str1']}</b>
	</td>
	<td><B>{$lang['tpl.str2']}</B>
	</td>
	</tr>
EOT;
	$ii = 0;
	while($vs = $db->fetch_array($query)){
		$voteoption = explode(',',$vs['voteoption']);
		$ii++;
		for($i=0; $i<=count($voteoption); $i++){
			if ( is_numeric($voteoption[$i]) ){
				if ( $i != 0 ){
					$votevaluestr .= '<br>';
				}
				$votevaluestr .= $votevalue[$voteoption[$i]];
			}
		}
	print <<<EOT
	<tr>
	<td align=center height=23><a href="dispuser.php?id={$vs['userid']}" target=_blank>{$vs['username']}</a>
	</td>
	<td>
	{$votevaluestr}
	</td>
	</tr>
EOT;
		$votevaluestr = '';
	}//endwhile
	if( $ii == 0 ){
	print <<<EOT
	<tr>
	<td colspan=2 height=23>{$lang['tpl.str3']}
	</td>
	</tr>
EOT;
	}
	print <<<EOT
	</table>
EOT;
} elseif (2 == $t) {
	view_Topic();
	if (is_numeric(REPLY_ID) AND REPLY_ID > 0) {
		view_Dispbbs();
	}
	FootInfo();
} else {
	$encodeusername = urlencode($pagerinfo['s_username']);
	is_numeric($pagerinfo['s_addtime']) AND ($pagerinfo['s_addtime'] = gmdate('Y-m-d H:i:s', $pagerinfo['s_addtime']+getUserTimeZoneOffset()));
	print <<<EOT
	<!--浏览小字报-->
	<table cellpadding="3" cellspacing="1" align="center" class="tableborder1" style="width:98%">
	<tr>
	<th height="24">{$pagerinfo['s_title']}</th>
	</tr>
	<tr>
	<td>
	<p align="center"><a href="dispuser.php?name={$encodeusername}" target="_blank">{$pagerinfo['s_username']}</a> {$lang['tpl.str12']} {$pagerinfo['s_addtime']}</p>
	<blockquote>
	<br />
		{$pagerinfo['s_content']}
	<br />
	<div align="right">{$lang['tpl.str13']}{$pagerinfo['s_hits']}</div>
	</blockquote>
	</td>
	</tr>
	<tr>
	<td height="24"><a href="#" onclick="window.close();">{$lang['tpl.str14']}</a></td>
	</tr>

	</table>
EOT;
}

function view_Topic()
{
	global $lang;
	$topicinfo =& GetTopicInfo();
	print <<<EOT
	<table  cellpadding="5" cellspacing="0" align="center" class="tableborder1" style="border-top:none;">
		<tr><th colspan=4 height=23>{$lang['tpl.str43']}{$topicinfo['title']}{$lang['tpl.str44']} {$lang['tpl.str15']}</th></tr>
		<tr><td class=tablebody6 width="20%" height=23 align=right>{$lang['tpl.str16']}</td>
		<td class=tablebody5 width="80%" colspan=3>
EOT;
	if (1 == $topicinfo['hidename']) {
		print $lang['tpl.str17'];
	} else {
		print $topicinfo['postusername'];
	}
	$topicinfo['dateandtime'] = gmdate("Y-m-d H:i:s",$topicinfo['dateandtime']+getUserTimeZoneOffset());
	print <<<EOT
	</td></tr>
	<tr><td class=tablebody6 height=23 align=right>{$lang['tpl.str18']}</td>
	<td class=tablebody5 colspan=3>{$topicinfo['dateandtime']}</td></tr>
	<tr>
	<td class=tablebody6 width="20%" height=23 align=right>{$lang['tpl.str19']}</td>
	<td class=tablebody5 width="30%">{$topicinfo['child']}</td>
	<td class=tablebody6 width="20%" align=right>{$lang['tpl.str20']}</td>
	<td class=tablebody5 width="30%">{$topicinfo['hits']}</td>
	</tr>
EOT;
	if ($topicinfo['getmoneytype'] > 0) {
		$strtmp1 = GetTopicMoneyInfo($topicinfo['getmoney'], $topicinfo['getmoneytype']);
		$strtmp2 = ShowBuyUser();
		print <<<EOT
		<tr><td class=tablebody6 height=23 align=right>{$lang['tpl.str21']}</td>
		<td class=tablebody5 colspan=3>{$strtmp1}</td></tr>
		<tr><td class=tablebody6 valign=top height=23 align=right>{$lang['tpl.str22']}</td>
		<td class=tablebody5 colspan=3>
		{$strtmp2}
		</td></tr>
EOT;
	}
	if (trim($topicinfo['usetools']) !== '' AND 1 == $fsetting['plus_tools']) {
		$toolsinfo =& GetTopicToolsInfo($topicinfo['usetools']);
		print <<<EOT
		<tr><td class=tablebody6 height=23 align=right>{$lang['tpl.str23']}</td>
		<td class=tablebody5 colspan=3><u>{$toolsinfo}</u></td></tr>
EOT;
	}
		print <<<EOT
	</table>
EOT;
}//end function view_Topic

function view_Dispbbs()
{
	global $lang;
	$replyinfo =& GetBBsReplyInfo();
	print <<<EOT
	<table  cellpadding=0 cellspacing=0 align=center class="mainbox tableborder">
		<tr><th colspan=2 height=23>{$lang['tpl.str24']}</th></tr>
		<tr><td class=tablebody6 width="20%" height=23 align=right>{$lang['tpl.str25']}</td><td class=tablebody5 width="80%" >
EOT;
	if (2 == $replyinfo['signflag']) {
		print $lang['tpl.str17'];
	} else {
		print UserInfoUrl($replyinfo['username']);
	}
	$replyinfo['dateandtime'] = gmdate("Y-m-d H:i:s",$replyinfo['dateandtime']+getUserTimeZoneOffset());
	print <<<EOT
		</td></tr>
		<tr><td class=tablebody6 height=23 align=right>{$lang['tpl.str26']}</td><td class=tablebody5>{$replyinfo['dateandtime']}</td></tr>
EOT;
	if (1 == $fsetting['plus_tools']) {
		$tempstr = GetTopicToolsInfo($replyinfo['usetools']);
		print <<<EOT
		<tr><td class=tablebody6 height=23 align=right>{$lang['tpl.str27']}</td><td class=tablebody5>{$tempstr}</td></tr>
EOT;
	}
	print <<<EOT
	</table>
EOT;
}//end function view_Dispbbs

function GetTopicMoneyInfo($m, $moneytype)	//	帖子信息类型
{
	global $lang;
	$tplstring = '';
	switch ($moneytype) {
		case 1:
			$tplstring = str_replace(array('{$SendMoney}', '{$Stats}'), array($m, ''), $lang['tpl.str6']);
			break;
		case 2:
			$tplstring = str_replace('{$GetMoney}', $m, $lang['tpl.str7']);
			break;
		case 3:
			$tplstring = str_replace('{$PayMoney}', $m, $lang['tpl.str8']);
			break;
		case 5:
			$tplstring = str_replace(array('{$SendMoney}', '{$Stats}'), array($m, $lang['tpl.str9']), $lang['tpl.str6']);
			break;
		default:
			break;
	}//end switch
	return $tplstring;
}//end function GetTopicMoneyInfo

function ShowBuyUser()
{
	global $lang;
	$bbsinfo =& GetBBsInfo();
	$postbuyuser = trim($bbsinfo['postbuyuser']);
	if ('' === $postbuyuser OR false === strpos($postbuyuser, '|||')) {
		return '';
	}
	$tempstr = explode('|||', htmlspecialchars($postbuyuser));
	$n = count($tempstr) -1 ;
	$topicinfo =& GetTopicInfo();
	$returnval = '';
	switch ($topicinfo['getmoneytype']) {
		case 1:
		case 5:
			$returnval .= $lang['tpl.str28'].$tempstr[0].$lang['tpl.str29'].($n - 1).'</b>'.$lang['tpl.str45'].'<br />';
			for ($i = 2; $i <= $n ; $i++) {
				$buyuser = explode(',', $tempstr[$i]);
				$returnval .= UserInfoUrl($buyuser[0]).$lang['tpl.str30'].$buyuser[1].'</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
				if (1 == $i % 2) {
					$returnval .= '<br />';
				}
			}//end for
			break;
		case 2:
			$returnval .= $lang['tpl.str31'].$tempstr[0].$lang['tpl.str32'].($n - 1).'</b>'.$lang['tpl.str45'].'<br />';
			for ($i = 2; $i <= $n ; $i++) {
				$buyuser = explode(',', $tempstr[$i]);
				$returnval .= UserInfoUrl($buyuser[0]).$lang['tpl.str33'].$buyuser[1].'</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
				if (1 == $i % 2) {
					$returnval .= '<br />';
				}
			}
			break;
		case 3:
			$buymoneyinfo = explode('@@@', $tempstr[0]);
			$buyinfo = '';
			$maxindex = count($buymoneyinfo) - 1;
			if ($maxindex > 0) {
				$getmoney = $buymoneyinfo[0];
				$buyinfo = $lang['tpl.str34'];
				if ($buymoneyinfo[1] != -1) {
					$buyinfo .= $buymoneyinfo[1].$lang['tpl.str45'];
				} else {
					$buyinfo .= $lang['tpl.str35'];
				}
				if ($buymoneyinfo[2] != 0) {
					$buyinfo .= $lang['tpl.str36'];
				} else {
					$buyinfo .= $lang['tpl.str37'];
				}
				if (trim($buymoneyinfo[3]) !== '') {
					$buyinfo .= $lang['tpl.str38'].$buymoneyinfo[3];
				}
				$buyinfo .= '<hr />';
			} else {
				$getmoney = $tempstr[0];
			}
			$returnval .= $buyinfo.'<br />'.$lang['tpl.str31'].$getmoney.'</b>'.$lang['tpl.str46'].$lang['tpl.str39'].'<b>'.($n - 2).'</b>'.$lang['tpl.str45'].'<br />';
			for ($i = 2; $i <= $n ; $i++) {
				$returnval .= UserInfoUrl($tempstr[$i]).'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
				if (1 == $i % 2) {
					$returnval .= '<br />';
				}
			}//end for
			break;
		default:
			break;
	}//end switch
	return $returnval;
}//end function ShowBuyUser

function UserInfoUrl($name)
{
	global $lang;
	return '<a href="dispuser.php?name='.urlencode($name).'" target="_blank"><u><b>'.$name.'</b></u></a>';
}//end function UserInfoUrl

function FootInfo()
{
	global $lang;
	print <<<EOT
		<table border="0" cellpadding=4 cellspacing=0 align=center Style="Width:99%">
			<tr><td align=center><input type="button" onclick="window.close()" value="{$lang['tpl.str40']}"></td></tr>
		</table>
EOT;
}//end function FootInfo

?>