<?php
	require("session_check.php");	
	require("../foundation/module_group.php");
	require("../foundation/fpages_bar.php");
	
	//数据表定义区
	$t_groups=$tablePreStr."groups";
	$t_group_type=$tablePreStr."group_type";

	$dbo = new dbex;
	dbtarget('w',$dbServs);
	
	//语言包引入
	$m_langpackage=new modulelp;		
	
	//当前页面参数
	$page_num=trim(get_argg('page'));
	
	//变量区
	$c_g_name=short_check(get_argg('g_name'));
	$c_g_id=intval(short_check(get_argg('g_id')));
	$c_group_type_name=short_check(get_argg('group_type_name'));
	$c_group_type=intval(short_check(get_argg('group_type')));
	$c_join_type=short_check(get_argg('join_type'));
	$c_min_members=intval(short_check(get_argg('min_members')));
	$c_max_members=intval(short_check(get_argg('max_members')));
	$c_min_subject=intval(short_check(get_argg('min_subject')));
	$c_max_subject=intval(short_check(get_argg('max_subject')));
	$c_min_comments=intval(short_check(get_argg('min_comments')));
	$c_max_comments=intval(short_check(get_argg('max_comments')));
	$c_order_by=short_check(get_argg('order_by'));
	$c_order_sc=short_check(get_argg('order_sc'));
	$c_perpage=get_argg('perpage') ? intval(short_check(get_argg('perpage'))):20;
	
	//缓存功能区
	require($webRoot.$baseLibsPath."model/group_type_list.model.cache.php");

	$sql="select group_id,group_creat_name,add_userid , group_pass,group_name,group_time,subjects_num,comments,group_type,member_count from $t_groups where 1=1 ";
	
	if(!empty($c_g_name)){
		$sql.=" and group_name like '%$c_g_name%' ";
		}
	
	if(!empty($c_g_id)){
		$sql.=" and group_id = $c_g_id ";
		}	
		
	if(!empty($c_group_type)){
		$sql.=" and group_type_id = $c_group_type ";
		}	

	if($c_join_type!=''){
		$sql.=" and group_join_type = $c_join_type ";
		}
		
	if(!empty($c_min_members)){
		$sql.=" and member_count >= $c_min_members ";
		}
		
	if(!empty($c_max_members)){
		$sql.=" and member_count <= $c_max_members ";
		}	
		
	if(!empty($c_min_subject)){
		$sql.=" and subjects_num >= $c_min_subject ";
		}	
		
	if(!empty($c_max_subject)){
		$sql.=" and subjects_num <= $c_max_subject ";
		}	
		
	if(!empty($c_min_comments)){
		$sql.=" and comments >= $c_min_comments ";
		}	
		
	if(!empty($c_max_comments)){
		$sql.=" and comments <= $c_max_comments";
		}
		
	if(!empty($c_order_by)){
		$sql.=" order by $c_order_by ";
		}
		
	$sql.=" $c_order_sc ";
	
	//设置分页
	$dbo->setPages($c_perpage,$page_num);	
	
	//取得数据
	$group_rs=$dbo->getRs($sql);	
	
	//分页总数
	$page_total=$dbo->totalPage;
	
	//加入方式
	$j_no_limit='';$j_free='';$j_check='';$j_reju='';
	if(get_argg('join_type')==''){$j_no_limit="selected";}
	if(get_argg('join_type')=='0'){$j_free="selected";}
	if(get_argg('join_type')=='1'){$j_check="selected";}
	if(get_argg('join_type')=='2'){$j_reju="selected";}
	
	//按字段排序
	$o_def='';$o_members='';$o_subjects='';$o_comments='';
	if(!get_argg('order_by')||get_argg('order_by')=="group_id"){$o_def="selected";}
	if(get_argg('order_by')=="member_count"){$o_members="selected";}
	if(get_argg('order_by')=="subjects_num"){$o_subjects="selected";}
	if(get_argg('order_by')=="comments"){$o_comments="selected";}	
		
	//排列方式
	$sc_desc='';$sc_asc='';
	if(get_argg('order_sc')==''||get_argg('order_sc')=="asc"){$sc_asc="selected";}
	if(get_argg('order_sc')=="desc"){$sc_desc="selected";}
	
	//分页显示条数
	$p_20='';$p_50='';$p_100='';
	if(!get_argg('perpage')||get_argg('perpage')=="20"){$p_20="selected";}
	if(get_argg('perpage')=="50"){$p_50="selected";}
	if(get_argg('perpage')=="100"){$p_100="selected";}
	
	//显示控制
	$isset_data="";
	$none_data="content_none";
	$isNull=0;
	if(empty($group_rs)){
		$isNull=1;
		$isset_data="content_none";
		$none_data="";
		}
?>

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="css/right.css">
</head>
<script type='text/javascript'>

function create_xmlhttp()
{
	if(window.ActiveXObject){
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}else{
			xmlhttp=new XMLHttpRequest();
			}
}
	
function lock_group(group_id,type_value)
{
	create_xmlhttp();
	xmlhttp.open("GET","group_lock.action.php?group_id="+group_id+"&type_value="+type_value,true);
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4&&xmlhttp.status==200){
			if(type_value==0){
				str="<font color='red'><?php echo $m_langpackage->m_lock;?></font>";document.getElementById("unlock_button_"+group_id).style.display="";document.getElementById("lock_button_"+group_id).style.display="none";
				}else{
					str="<?php echo $m_langpackage->m_normal;?>";document.getElementById("unlock_button_"+group_id).style.display="none";document.getElementById("lock_button_"+group_id).style.display="";
					}
			window.document.getElementById("state_"+group_id).innerHTML=str;
		}
	}
	xmlhttp.send(null);
}	
</script>

<body>
	
<div class="container">
	<div class="rs_head"><?php echo $m_langpackage->m_check_condition;?></div>
</div>

<form action="" method="GET">
	<table class='main main_left'>
		<tr>
			<th width=12%> <?php echo $m_langpackage->m_name;?><font color=red>*</font></th>
			<td width=30%><input type=text name='g_name' value='<?php echo get_argg('g_name');?>' /></td>
			<th width=12%> <?php echo $m_langpackage->m_group_id;?></th>
			<td width=*><input type=text name='g_id' value='<?php echo get_argg('g_id');?>' /></td>
		</tr>
		<tr>
			<th> <?php echo $m_langpackage->m_type;?></th>
			<td>
				<input type='hidden' name='group_type_name' id='group_type_name' />
				<?php echo group_sort_list($dbo,$t_group_type,$c_group_type);?>
			</td>
			<th> <?php echo $m_langpackage->m_join_type;?></th>
			<td><select name='join_type'>
						<option value="" <?php echo $j_no_limit;?>><?php echo $m_langpackage->m_astrict_no;?></option>
						<option value="0" <?php echo $j_free;?>><?php echo $m_langpackage->m_free_join;?></option>
						<option value="1" <?php echo $j_check;?>><?php echo $m_langpackage->m_check_join;?></option>
						<option value="2" <?php echo $j_reju;?>><?php echo $m_langpackage->m_check_rejuse;?></option>
					</select>
			</td>				
		</tr>
		<tr>
			<th> <?php echo $m_langpackage->m_member_num;?></th>
			<td>
				<input type='text' name='min_members' size='6' value='<?php echo get_argg('min_members');?>' />~<input type='text' name='max_members' size='6' value='<?php echo get_argg('max_members');?>' />
			</td>			
		</tr>
		<tr>	
			<th> <?php echo $m_langpackage->m_sub_num;?></th>
			<td>
				<input type='text' name='min_subject' size='6' value='<?php echo get_argg('min_subject');?>' />~<input type='text' name='max_subject' size='6' value='<?php echo get_argg('max_subject');?>' />
			</td>	
		</tr>
		<tr>	
			<th> <?php echo $m_langpackage->m_comments;?></th>
			<td>
				<input type='text' name='min_comments' size='6' value='<?php echo get_argg('min_comments');?>' />~<input type='text' name='max_comments' size='6' value='<?php echo get_argg('max_comments');?>' />
			</td>		
		</tr>
		<tr>
			<th><?php echo $m_langpackage->m_result_order;?></th>
			<td colSpan=3>
				<select name='order_by'>
					<option value="group_id" <?php echo $o_def;?>><?php echo $m_langpackage->m_def_order;?></option>
					<option value="member_count" <?php echo $o_members;?>><?php echo $m_langpackage->m_member_num;?></option>
					<option value="subjects_num" <?php echo $o_subjects;?>><?php echo $m_langpackage->m_sub_num;?></option>
					<option value="comments" <?php echo $o_comments;?>><?php echo $m_langpackage->m_comments;?></option>
				</select>

				<select name='order_sc'>
					<option value='asc' <?php echo $sc_asc;?>><?php echo $m_langpackage->m_asc;?></option>
					<option value='desc' <?php echo $sc_desc;?>><?php echo $m_langpackage->m_desc;?></option>
				</select>
				
				<select name='perpage'>
					<option value='20' <?php echo $p_20;?>><?php echo $m_langpackage->m_page_20;?></option>
					<option value='50' <?php echo $p_50;?>><?php echo $m_langpackage->m_page_50;?></option>
					<option value='100' <?php echo $p_100;?>><?php echo $m_langpackage->m_page_100;?></option>
				</select>
				<input type='submit' value="<?php echo $m_langpackage->m_search;?>" class="button" />
			</td>
		</tr>
  	<tr><td colspan=2><?php echo $m_langpackage->m_red;?></td></tr>		
		
		
	</table>
</form>
	
	
<div class="container">
	<div class="rs_head"><?php echo $m_langpackage->m_group_list;?></div>
</div>

	<table class='main <?php echo $isset_data;?>'>
		<tr><th><?php echo $m_langpackage->m_name;?></th><th><?php echo $m_langpackage->m_type;?></th><th><?php echo $m_langpackage->m_greator;?></th><th><?php echo $m_langpackage->m_great_date;?></th><th><?php echo $m_langpackage->m_member_num;?></th><th><?php echo $m_langpackage->m_sub_num;?></th><th><?php echo $m_langpackage->m_comments;?></th><th><?php echo $m_langpackage->m_state;?></th><th><?php echo $m_langpackage->m_ctrl;?></th></tr>
	<?php foreach($group_rs as $rs){?>
		<tr>
			<td>
				<a href='../home.php?h=<?php echo $rs['add_userid'];?>&app=group_space&group_id=<?php echo $rs['group_id'];?>&user_id=<?php echo $rs['add_userid'];?>' target='_blank'>
					<?php echo $rs['group_name'];?>
				</a>
			</td>
			<td><?php echo $rs['group_type'];?></td>
			<td><?php echo $rs['group_creat_name'];?></td>
			<td><?php echo $rs['group_time'];?></td>
			<td><?php echo $rs['member_count'];?></td>
			<td><?php echo $rs['subjects_num'];?></td>
			<td><?php echo $rs['comments'];?></td>
			<td><span id="state_<?php echo $rs['group_id'];?>"><?php if($rs['group_pass']==1)echo $m_langpackage->m_normal;else echo "<font color='red'>$m_langpackage->m_lock</font>";?></span></td>
			<td>
				<a href='../home.php?h=<?php echo $rs['add_userid'];?>&app=group_space&group_id=<?php echo $rs['group_id'];?>&user_id=<?php echo $rs['add_userid'];?>' target='_blank'>
					<image src="images/more.gif" title="<?php echo $m_langpackage->m_more;?>" alt="<?php echo $m_langpackage->m_more;?>" />
				</a>
				
				<?php $unlock="display:none";$lock=""; if($rs['group_pass']==0){$unlock="";$lock="display:none";}?>
				
				<span id="unlock_button_<?php echo $rs['group_id'];?>" style="<?php echo $unlock;?>"><a href="javascript:lock_group(<?php echo $rs['group_id'];?>,1);"><img title="<?php echo $m_langpackage->m_unlock;?>" src="images/unlock.png" /></a></span>
				
				<span id="lock_button_<?php echo $rs['group_id'];?>" style="<?php echo $lock;?>"><a href="javascript:lock_group(<?php echo $rs['group_id'];?>,0);" onClick="return confirm('<?php echo $m_langpackage->m_ask_lock;?>');"><img title="<?php echo $m_langpackage->m_lock;?>" src="images/lock.png" /></a></span>				
			</td>
		</tr>
	<?php
		}
	?>
		<tr>
			<td colspan=9 style="text-align:'right'">
			<?php
				page_show($isNull,$page_num,$page_total);
			?>
			</td>
		</tr>	
	</table>
	
	<div class='guide_info <?php echo $none_data;?>'><?php echo $m_langpackage->m_none_data;?></div>

</body>
</html>		