<?php 
	require("session_check.php");	
	require("../foundation/fpages_bar.php");
	
	//语言包引入
	$m_langpackage=new modulelp;
	
	//数据表定义区
	if(get_argg('idtype')=="picid"){
		$t_table=$tablePreStr."photo_comment";
		$con_id="photo_id";
	}else
	if(get_argg('idtype')=="blogid" or !get_argg('idtype')){
		$t_table=$tablePreStr."blog_comment";
		$con_id="log_id";
	}else
	if(get_argg('idtype')=="albid"){
		$t_table=$tablePreStr."album_comment";
		$con_id="album_id";
	}else
	if(get_argg('idtype')=="gropid"){
		$t_table=$tablePreStr."group_subject_comment";
		$con_id="subject_id";
	}else
	if(get_argg('idtype')=="pollid"){
		$t_table=$tablePreStr."poll_comment";
		$con_id="p_id";
	}else
	if(get_argg('idtype')=="shaid"){
		$t_table=$tablePreStr."share_comment";
		$con_id="s_id";
	}else
	if(get_argg('idtype')=="moodid"){
		$t_table=$tablePreStr."mood_comment";
		$con_id="mood_id";		
	}

	$dbo = new dbex;
	dbtarget('w',$dbServs);
	
	//当前页面参数
	$page_num=trim(get_argg('page'));
	
	//变量区
	$c_pid=intval(short_check(get_argg('pid')));
	$c_aid=intval(short_check(get_argg('aid')));
	$c_conid=intval(short_check(get_argg('conid')));
	$c_uid=intval(short_check(get_argg('uid')));
	$c_authorid=intval(short_check(get_argg('authorid')));
	$c_author=short_check(get_argg('author'));
	$c_message=short_check(get_argg('message'));
	$c_dateline1=short_check(get_argg('dateline1')); 
	$c_dateline2=short_check(get_argg('dateline2'));
	$c_orderby=short_check(get_argg('orderby'));
	$c_ordersc=short_check(get_argg('ordersc')); 
	$c_perpage=get_argg('perpage') ? intval(short_check(get_argg('perpage'))):20;
	
	$sql="select * from $t_table where 1=1 ";
	
	if(!empty($c_pid)){
		$sql.=" and photo_id = $c_pid ";
	}
	if(!empty($c_aid)){
		$sql.=" and album_id = $c_aid ";
	}
	if(!empty($c_conid)){
		$sql.=" and $con_id = $c_conid ";
	}
	if(!empty($c_author)){
		$sql.=" and visitor_name = '$c_author' ";
	}		
	if(!empty($c_authorid)){
		$sql.=" and visitor_id = $c_authorid ";
	}
	if(!empty($c_uid)){
		$sql.=" and host_id = $c_uid ";
	}
	if(!empty($c_message)){
		$sql.=" and content like '%$c_message%' ";
	}
	if(!empty($c_dateline1)){
		$sql.=" and date(add_time) >= '$c_dateline1' ";
	}
	if(!empty($c_dateline2)){
		$sql.=" and date(add_time) <= '$c_dateline2' ";
	}
	if(!empty($c_orderby)){
		$sql.=" order by $c_orderby ";
	}
		
	$sql.=" $c_ordersc ";
	$dbo->setPages($c_perpage,$page_num);//设置分页
	$com_rs=$dbo->getRs($sql);
	$page_total=$dbo->totalPage;//分页总数
	
	//条件显示
	$l_gro='';$l_blg='';$l_pic='';$l_alb='';$l_poll='';$l_sha='';$l_mood='';
	if(get_argg('idtype')=="gropid"){$l_gro="selected";}
	if(get_argg('idtype')=="blogid"){$l_blg="selected";}
	if(get_argg('idtype')=="picid"){$l_pic="selected";}
	if(get_argg('idtype')=="albid"){$l_alb="selected";}
	if(get_argg('idtype')=="pollid"){$l_poll="selected";}
	if(get_argg('idtype')=="shaid"){$l_sha="selected";}
	if(get_argg('idtype')=="moodid"){$l_mood="selected";}
	
	//按字段排序
	$o_def='';$o_add_time='';
	if(get_argg('orderby')==''||get_argg('order_by')=="com_id"){$o_def="selected";}
	if(get_argg('orderby')=="add_time"){$o_add_time="selected";}
	
	//排列方式
	$sc_desc='';$sc_asc='';
	if(get_argg('ordersc')=="desc"){$sc_desc="selected";}
	if(!get_argg('ordersc')||get_argg('ordersc')=="asc"){$sc_asc="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($com_rs)){
		$isNull=1;
		$isset_data="content_none";
		$none_data="";
	}
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/right.css">
<title>无标题文档</title>
</head>
<script type='text/javascript' src='../servtools/calendar.js'></script>
<script type='text/javascript'>
function create_xmlhttp()
{
	if(window.ActiveXObject){
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		xmlhttp=new XMLHttpRequest();
	}
}
function del_com(comment_id,idtype,v_id,main_id)
{
	 create_xmlhttp();
	 xmlhttp.open("GET","com_del.action.php?cid="+comment_id+"&type="+idtype+"&v_id="+v_id+"&main_id="+main_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_"+comment_id).innerHTML=return_text;
	 	 }
	 }
	 xmlhttp.send(null);
}
function check_form()
{
	var dateline1=document.getElementById("dateline1").value;
	var dateline2=document.getElementById("dateline2").value;
	var time_format=/\d{4}\-\d{2}\-\d{2}/;
	if(dateline1){
		if(!time_format.test(dateline1)){
			alert("<?php echo $m_langpackage->m_date_wrong?>");
			return false;
		}
	}
	
	if(dateline2){
		if(!time_format.test(dateline2)){
			alert("<?php echo $m_langpackage->m_date_wrong?>");
			return false;
		}
	}
}
</script>
<body>
<div class="container">
	<div class="rs_head"><?php echo $m_langpackage->m_check_condition?></div>
</div>

<form method="get" action=""  onsubmit="return check_form()">
<TABLE class="main main_left">
<tr>
<th width=12%><?php echo $m_langpackage->m_com_type?></th>
<td width=30%>
<select name="idtype">
	<option value="blogid" <?php echo $l_blg;?>><?php echo $m_langpackage->m_blog?></option>
	<option value="gropid" <?php echo $l_gro;?>><?php echo $m_langpackage->m_subject?></option>
	<option value="albid" <?php echo $l_alb;?>><?php echo $m_langpackage->m_album?></option>
	<option value="picid" <?php echo $l_pic;?>><?php echo $m_langpackage->m_photo?></option>
	<option value="pollid" <?php echo $l_poll;?>><?php echo $m_langpackage->m_poll?></option>
	<option value="shaid" <?php echo $l_sha;?>><?php echo $m_langpackage->m_share?></option>
	<option value="moodid" <?php echo $l_mood;?>><?php echo $m_langpackage->m_mood?></option>
</select>
<th width=10%><span style="text-align:left"><?php echo $m_langpackage->m_com_by_id?></span></th>
<td width=*><input type="text" name="conid" value="<?php echo get_argg('conid');?>"></td>
</tr>
<tr><th><?php echo $m_langpackage->m_com_uid?></th><td><input type="text" name="authorid" value="<?php echo get_argg('authorid');?>"></td>
<th><?php echo $m_langpackage->m_com_name?></th><td><input type="text" name="author" value="<?php echo get_argg('author');?>"></td>
</tr>
<tr><th><?php echo $m_langpackage->m_com_by_uid?></th><td><input type="text" name="uid" value="<?php echo get_argg('uid');?>"></td>
<th><?php echo $m_langpackage->m_issue_time?></th><td>
<input type="text" name="dateline1" AUTOCOMPLETE=off onclick='getDateString(this,oCalendarChs)' value="<?php echo get_argg('dateline1');?>" size="10"> ~
<input type="text" name="dateline2" AUTOCOMPLETE=off onclick='getDateString(this,oCalendarChs)' value="<?php echo get_argg('dateline2');?>" size="10"> (YYYY-MM-DD)
</td>	
</tr>
<tr><th><?php echo $m_langpackage->m_content?><font color=red>*</font></th><td><input type="text" name="message" value="<?php echo get_argg('message');?>"></td>
</tr>
 
<tr><th><?php echo $m_langpackage->m_result_order?></th>
<td colspan="3">
<select name="orderby">
	<OPTION value="comment_id" <?php echo $o_def;?>><?php echo $m_langpackage->m_def_order?></OPTION>
	<OPTION value='add_time' <?php echo $o_add_time;?>><?php echo $m_langpackage->m_com_time?></OPTION> 
</select>
<select name="ordersc">
    <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>
</table>
</form>

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

<form method="post" action="">
<table border="0" class='main <?php echo $isset_data;?>'>
<?php 
$isNull=1;
foreach($com_rs as $val){
	$isNull=0;
?>
<tr>
<td width="90%"  style='text-align:left'>
<?php echo $val['visitor_name'];?>： <?php echo $val['content'];?>
<br />
<?php echo $m_langpackage->m_com_by_id?>: <?php echo $con_id;?>-<?php echo $val[$con_id];?>  
<?php echo $m_langpackage->m_com_by_uid?>: <a href="../home.php?h=<?php echo $val['host_id'];?>" target="_blank">user_id-<?php echo $val['host_id'];?></a>  
<?php echo $val['add_time'];?>
</td>
<td width="*" style='text-align:left'>
<div id="operate_<?php echo $val['comment_id'];?>">
<a href='javascript:del_com(<?php echo $val['comment_id'];?>,"<?php echo get_argg('idtype');?>",<?php echo $val['visitor_id'];?>,<?php echo $val[$con_id];?>);' onclick='return confirm("<?php echo $m_langpackage->m_ask_del?>");'><img src='images/del.png' /></a>
</div>
</td>
</tr>
<tr><td colspan="2" style="border-bottom:1px #999999 dotted;line-height:3px;">&nbsp</td></tr>
<?php 
}
?>

<tr>
	<td colspan=5 style="text-align:'right'">
	<?php
		page_show($isNull,$page_num,$page_total);
	?>
	</td>
</tr>
</table>
</form>
<div class='guide_info <?php echo $none_data;?>'><?php echo $m_langpackage->m_none_data?></div>
</body>
</html>
