<?php
define('THIS_SCRIPT', 'indivgroup_member');
require_once 'global.php';
include_once $fsetting['manageurl'].'inc/page.class.php';
$lang = load_lang($lang, 'indivgroup_member' );
global $title_num,$action,$reaction,$membername;
include_once CACHE_PATH.'board/board_all.php';
$board_settings = $_DCACHE['forum_settings'][$fsetting['indivgroup_set']]['setting'];
include_once INC_PATH.'DV_Encoding.class.php';
$objenc =& DV_Encoding::GetEncoding($charset);

$groupid= intval($_GET['groupid']);
$query=$db->query("select id,groupname,appuserid,appusername,usernum,stats,postnum,topicnum,todaynum,yesterdaynum,limituser,appdate,passdate,visidate,locked,viewflag,groupface from {$dv}group_name where id={$groupid}");

if ($arr=$db->fetch_array($query)){
	$groupinfo=$arr;
	$title_num = array(0=>array('linktitle'=>$lang['template.strings0'],'linkurl'=>'indivgroup.php'),1=>array('linktitle'=>$groupinfo['groupname'],'linkurl'=>'indivgroup_index.php?groupid='.$groupinfo['id']),2=>array('linktitle'=>$lang['template.strings1']));
	head(1,0,0,$title_num);
}
else{
	head();
	showmsg($lang['tpl.str45']);
}

if($fsetting['indivgroup_show'] == 0)
{
	showmsg($lang['error_close']);
}

if($groupid == 0){
	showmsg($lang['tpl.str45']);
}

group_userlist();
footer();

function group_userlist(){
	global $dv,$db,$lang,$page,$total,$page_size,$offset,$page_count,$p,$userid,$membername,$boardmaster,$board_settings,$groupnum,$objenc,$groupid;
	$user_list= array();
	$admin_list= array();
	$admin2_list= array();
	if ($board_settings[60] <= 0) {
		$board_settings[60] = 30;
	}

	if ($page == '' || !is_numeric($page) || $page <= 0){
		$page = 1;
	}

	//用户列表
	$userids= '';
	$query=$db->query("Select /*!40001 SQL_CACHE */ userid,username From {$dv}group_user where groupid={$groupid} and islock=1 order by id desc",array('absolutePage'=>$page,'pageSize'=>$board_settings[60]));

	$usernum=$db->scalar("Select count(id) From {$dv}group_user where groupid={$groupid} and islock=1");

	while ($arr=$db->fetch_array($query)){
		if($userids == '')
			$userids= $arr['userid'];
		else
			$userids.= ','.$arr['userid'];
	}


	if($userids != ''){
		$sql= "select /*!40001 SQL_CACHE */ userid,username,userface,userphoto from {$dv}user where userid in({$userids})";
		if($query=$db->query($sql)){
			while ($arr=$db->fetch_array($query)){
				if ( $objenc->StrLength($arr['username']) > 5){
					$arr['username'] = $objenc->SubString(strip_tags($arr['username']), 0, 4).'...';
				}
				$arrpic= explode("|",$arr['userface']);
				is_array($arrpic) AND $arr['userface']= $arrpic[count($arrpic)-1];
				$user_list[]=$arr;
			}
		}
	}

	//管理员列表
	$adminids= '';
	$sql= "select /*!40001 SQL_CACHE */ userid,username from {$dv}group_user where groupid={$groupid} and islock=2";
	if($query=$db->query($sql)){
		while ($arr=$db->fetch_array($query)){
			if ( $objenc->StrLength($arr['username']) > 6){
				$arr['username'] = $objenc->SubString(strip_tags($arr['username']), 0, 6).'...';
			}
			$admin_list[]=$arr;
			if($adminids == '')
				$adminids= $arr['userid'];
			else
				$adminids.= ','.$arr['userid'];
		}
	}

	if($page == 1){
		if($adminids != ''){
			$sql= "select /*!40001 SQL_CACHE */ userid,username,userface,userphoto from {$dv}user where userid in({$adminids})";
			if($query=$db->query($sql)){
				while ($arr=$db->fetch_array($query)){
					if ( $objenc->StrLength($arr['username']) > 5){
						$arr['username'] = $objenc->SubString(strip_tags($arr['username']), 0, 4).'...';
					}
					$arrpic= explode("|",$arr['userface']);
					is_array($arrpic) AND $arr['userface']= $arrpic[count($arrpic)-1];
					$admin_list2[]=$arr;
				}
			}
		}
	}

	$query=$db->query("Select /*!40001 SQL_CACHE */ topicid,groupid,boardid,title,hits From {$dv}group_topic Where groupid={$groupid} Order By lastposttime Desc Limit 10");
	while($result = $db->fetch_array($query)){
		$result['title'] = ChkBadWords($result['title']);
		$result['locktopic'] = htmlspecialchars($result['title']);

		if ( $objenc->StrLength($result['title']) > 12){
			$result['title'] = $objenc->SubString(strip_tags($result['title']), 0, 10).'...';
		}

		$_topics[] = $result;
	}

	$db->free_result($query);

	require_once printout('indivgroup_member');
}

?>