<?php
	require("session_check.php");	
	require("../foundation/fpages_bar.php");

	//语言包引入
	$m_langpackage=new modulelp;
	
	//表定义区
	$t_subject=$tablePreStr."group_subject";
	$t_group=$tablePreStr."groups";
	
	$dbo = new dbex;
	dbtarget('w',$dbServs);

	//当前页面参数
	$page_num=trim(get_argg('page'));	
	
	//变量区
	$c_g_id=intval(short_check(get_argg('g_id')));
	$c_s_title=short_check(get_argg('s_title'));
	$c_uid=intval(short_check(get_argg('uid')));
	$c_uname=short_check(get_argg('uname'));
	$c_s_id=intval(short_check(get_argg('s_id')));
	$c_min_send_date=short_check(get_argg('min_send_date'));
	$c_max_send_date=short_check(get_argg('max_send_date'));
	$c_max_hits=intval(short_check(get_argg('max_hits')));
	$c_min_hits=intval(short_check(get_argg('min_hits')));
	$c_max_comments=intval(short_check(get_argg('max_comments')));
	$c_min_comments=intval(short_check(get_argg('min_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;
	
	$sql="select s.subject_id , s.user_id  , s.group_id , g.add_userid , s.user_name , s.title , s.add_time , s.hits , s.comments , g.group_name from $t_subject as s join $t_group as g on (s.group_id=g.group_id) where 1=1 ";
	
	if(!empty($c_uid)){
		$sql.=" and s.user_id = $c_uid ";
	}
		
	if(!empty($c_uname)){
		$sql.=" and s.user_name like '%$c_uname%' ";
	}
		
	if(!empty($c_g_id)){
		$sql.=" and s.group_id = $c_g_id ";
	}
		
	if(!empty($c_s_title)){
		$sql.=" and s.title like '%$c_s_title%' ";
	}
		
	if(!empty($c_s_id)){
		$sql.=" and s.subject_id = $c_s_id ";
	}	
			
	if(!empty($c_min_send_date)){			
		$sql.=" and date(s.add_time) >= '$c_min_send_date' ";
	}
	
	if(!empty($c_max_send_date)){
		$sql.=" and date(s.add_time) <= '$c_max_send_date' ";
	}
	
	if(!empty($c_min_hits)){
		$sql.=" and s.hits >= $c_min_hits ";
	}
		
	if(!empty($c_max_hits)){	
		$sql.=" and s.hits <= $c_max_hits ";
	}
		
	if(!empty($c_min_comments)){
		$sql.=" and s.comments >= $c_min_comments ";
	}
		     
	if(!empty($c_max_comments)){
		$sql.=" and s.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);
	
	//取得数据
	$subject_rs=$dbo->getRs($sql);
	
	//分页总数
	$page_total=$dbo->totalPage;
	
	//按字段排序
	$o_def='';$o_s_date='';$o_hits='';$o_comments='';
	if(!get_argg('order_by')||get_argg('order_by')=="subject_id"){$o_def="selected";}
	if(get_argg('order_by')=="add_time"){$o_s_date="selected";}
	if(get_argg('order_by')=="hits"){$o_hits="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($subject_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' src='../servtools/calendar.js'></script>
<script type='text/javascript'>
	
function check_form(){
	var min_send_date=document.getElementById("min_send_date").value;
	var max_send_date=document.getElementById("max_send_date").value;
	var time_format=/\d{4}\-\d{2}\-\d{2}/;
	if(min_send_date){
		if(!time_format.test(min_send_date)){
			alert("<?php echo $m_langpackage->m_date_wrong?>");
			return false;
		}
	}
	
	if(max_send_date){
		if(!time_format.test(max_send_date)){
			alert("<?php echo $m_langpackage->m_date_wrong?>");
			return false;
		}
	}
}
	
function create_xmlhttp()
{
	if(window.ActiveXObject){
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		xmlhttp=new XMLHttpRequest();
	}
}

function del_subject(subject_id,group_id,sendor_id)
{
	create_xmlhttp();
	xmlhttp.open("GET","subject_del.action.php?subject_id="+subject_id+"&group_id="+group_id+"&sendor_id="+sendor_id,true);
	xmlhttp.onreadystatechange=function(){	 
		if(xmlhttp.readyState==4&&xmlhttp.status==200){
			var return_str=xmlhttp.responseText;
			var	return_text=return_str.replace(/[\s\n\r]/g,"");
			window.document.getElementById("operate_"+subject_id).innerHTML=return_text;
		}
	}
	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" onsubmit='return check_form()'>
<TABLE class="main main_left">
  <TBODY>
  <TR>
    <th width=12%><?php echo $m_langpackage->m_group_id?></th>
    <TD width=30%><INPUT type='text' name='g_id' value='<?php echo get_argg('g_id');?>'></TD>
    <th width=12%><?php echo $m_langpackage->m_title?><font color=red>*</font></th>
    <TD width=*><INPUT type='text' name='s_title' value='<?php echo get_argg('s_title');?>'></TD></TR>
  <TR>
    <th><?php echo $m_langpackage->m_author_id?></th>
    <TD><INPUT type='text' name='uid' value='<?php echo get_argg('uid');?>'></TD>
    <th><?php echo $m_langpackage->m_author_name?></th>
    <TD><INPUT type='text' name='uname' value='<?php echo get_argg('uname');?>'></TD></TR>
  <TR>
    <th><?php echo $m_langpackage->m_sub_id?></th>
    <TD><INPUT type='text' name='s_id' value='<?php echo get_argg('s_id');?>'> </TD>
    <th><?php echo $m_langpackage->m_issue_time?></th>
    <TD>
    	<INPUT type='text' size=10 name='min_send_date' AUTOCOMPLETE=off onclick='getDateString(this,oCalendarChs)' id='min_send_date' value='<?php echo get_argg('min_send_date');?>'> ~ <INPUT type='text' size=10 name='max_send_date' id='max_send_date' value='<?php echo get_argg('max_send_date');?>'> (YYYY-MM-DD) </TD>    
  </TR>

  <TR>
    <th><?php echo $m_langpackage->m_see_num?></th>
    <TD colSpan=3>
    	<INPUT type='text' size=10 name='min_hits' value='<?php echo get_argg('min_hits');?>'> ~ <INPUT type='text' size=10 name='max_hits' value='<?php echo get_argg('max_hits');?>'> </TD></TR>
  <TR>
    <th><?php echo $m_langpackage->m_reply_num?></th>
    <TD colSpan=3>
    	<INPUT type='text' size=10 name='min_comments' value='<?php echo get_argg('min_comments');?>'> ~ <INPUT type='text' size=10 name='max_comments' value='<?php echo get_argg('max_comments');?>'> </TD></TR>
  <TR>
<tr><th><?php echo $m_langpackage->m_result_order?></th>
<td colspan="3">
<select name="order_by">
	<OPTION value="subject_id" <?php echo $o_def;?>><?php echo $m_langpackage->m_def_order?></OPTION>
    <OPTION value="add_time" <?php echo $o_s_date;?>><?php echo $m_langpackage->m_issue_time?></OPTION> 
    <OPTION value="hits" <?php echo $o_hits;?>><?php echo $m_langpackage->m_see_num?></OPTION> 
    <OPTION value="comments" <?php echo $o_comments;?>><?php echo $m_langpackage->m_reply_num?></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" name="searchsubmit" value="<?php echo $m_langpackage->m_search?>" class="submit">
	</TD>
	</TR>
<tr><td colspan=2><?php echo $m_langpackage->m_red?></td></tr>	
	</TBODY>
	</TABLE>
</form>

<div class="container">
	<div class="rs_head"><?php echo $m_langpackage->m_sub_list?></div>
</div>

<table class='main <?php echo $isset_data;?>'>
	<tr>
		<th> <?php echo $m_langpackage->m_title?> </th><th> <?php echo $m_langpackage->m_author?> </th>
		<th> <?php echo $m_langpackage->m_reply?> </th><th> <?php echo $m_langpackage->m_see?> </th>
		<th> <?php echo $m_langpackage->m_issue_time?> </th><th width="15%"> <?php echo $m_langpackage->m_handle?> </th>
	</tr>
	<?php 
	foreach($subject_rs as $rs){
		?>
	<tr>
		<td style='text-align:left'>[ 
			<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>
			] &nbsp
			<a href='../home.php?h=<?php echo $rs['user_id'];?>&app=group_sub_show&group_id=<?php echo $rs['group_id'];?>&subject_id=<?php echo $rs['subject_id'];?>&user_id=<?php echo $rs['user_id'];?>' target='_blank'> 
				<?php echo $rs['title'];?>
			</a>
		</td>
		<td><?php echo $rs['user_name'];?></td>
		<td><?php echo $rs['comments'];?></td>
		<td><?php echo $rs['hits'];?></td>
		<td><?php echo $rs['add_time'];?></td>
		<td>
			<div id="operate_<?php echo $rs['subject_id'];?>">
				<a href='../home.php?h=<?php echo $rs['user_id'];?>&app=group_sub_show&group_id=<?php echo $rs['group_id'];?>&subject_id=<?php echo $rs['subject_id'];?>&user_id=<?php echo $rs['user_id'];?>' target='_blank'> 
					<image src="images/more.gif" title="<?php echo $m_langpackage->m_see_particular?>" alt="<?php echo $m_langpackage->m_see_particular?>" />
				</a>
				<a href='javascript:del_subject(<?php echo $rs['subject_id'];?>,<?php echo $rs['group_id'];?>,<?php echo $rs['user_id'];?>)' onclick='return confirm("<?php echo $m_langpackage->m_ask_del?>");' title='<?php echo $m_langpackage->m_del?>'><img src='images/del.png' /></a>
			</div>
		</td>
	</tr>
	<?php 
		}
	?>
	<tr>
		<td colspan=8 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>