<?php
//ask

require_once './include/common.inc.php';

$nav = $sitename;
//问答分类
$query = "select id, name, reid from {$cfg_dbprefix}asktype order by disorder asc, id asc";
$dsql->Execute('me',$query);
$tids = $tid2s = $asktypes = array();
while($asktype = $dsql->getarray())
{
	if($asktype['reid'] == 0)
	{
		$tids[] = $asktype;
	}else
	{
		$tid2s[] = $asktype;
	}

}
foreach($tids as $tid)
{
	$asktypes[] = $tid;
	$temp = 1;
	foreach($tid2s as $key => $tid2)
	{
		if($tid2['reid'] == $tid['id'])
		{
			if($temp > $cfg_ask_subtypenum) break;
			$temp ++ ;
			$asktypes[] = $tid2;
			unset($tid2s[$key]);
		}
	}
}

//未解决的问题数
$query = "select count(*) as total from {$cfg_dbprefix}ask where status=0";
$result = $dsql->getone($query);
$solvingnum = $result['total'];

//已解决的问题数
$query = "select count(*) as total from {$cfg_dbprefix}ask where status!=0";
$result = $dsql->getone($query);
$solvednum = $result['total'];

$nums = 8;
//精彩推荐
$query = "select id, tid, tidname, tid2, tid2name, title from {$cfg_dbprefix}ask where digest=1 order by dateline desc limit $nums";
$dsql->Execute('me',$query);
$digests = array();
while($row = $dsql->getarray())
{
	$row['title'] = cn_substr($row['title'],40);
	$digests[] = $row;
}

//新解决的问题
$query = "select id, tid, tidname, tid2, tid2name, title from {$cfg_dbprefix}ask where status=1 order by solvetime desc limit $nums";
$dsql->Execute('me',$query);
$solvedasks = array();
while($row = $dsql->getarray())
{
	$row['title'] = cn_substr($row['title'],40);
	$solvedasks[] = $row;
}

//待解决的问题
$query = "select id, tid, tidname, tid2, tid2name, title from {$cfg_dbprefix}ask where status=0 order by disorder desc, dateline desc limit $nums";
$dsql->Execute('me',$query);
$solvingasks = array();
while($row = $dsql->getarray())
{
	$row['title'] = cn_substr($row['title'],40);
	$solvingasks[] = $row;
}

//高分问题
$query = "select id, tid, tidname, tid2, tid2name, title from {$cfg_dbprefix}ask where status=0 order by reward desc limit $nums";
$dsql->Execute('me',$query);
$highrewardasks = array();
while($row = $dsql->getarray())
{
	$row['title'] = cn_substr($row['title'],40);
	$highrewardasks[] = $row;
}

//会员排行
$query = "select ID, userid, scores from {$cfg_dbprefix}member order by scores desc limit 20";
$dsql->Execute('me',$query);
$topmembers = array();
while($row = $dsql->getarray())
{
	$topmembers[] = $row;
}
$dsql->Close();
include DEDE.'./template/default/dede.htm';

?>