<?php
	require("session_check.php");	
	require("../foundation/fpages_bar.php");
	
	//数据表定义区
	$t_poll=$tablePreStr."poll";

	$dbo = new dbex;
	dbtarget('w',$dbServs);
	
	//语言包引入
	$m_langpackage=new modulelp;	
	
	//当前页面参数
	$page_num=trim(get_argg('page'));
	
	//变量区
	$c_subject=short_check(get_argg('subject'));
	$c_pid=intval(short_check(get_argg('pid')));
	$c_uid=intval(short_check(get_argg('uid')));
	$c_username=short_check(get_argg('username'));
	$c_noreply=short_check(get_argg('noreply'));
	$c_sex=short_check(get_argg('sex'));
	$c_expiration=short_check(get_argg('expiration'));
	$c_min_credit=intval(short_check(get_argg('min_credit')));
	$c_max_credit=intval(short_check(get_argg('max_credit')));
	$c_min_voternum=intval(short_check(get_argg('min_voternum')));
	$c_max_voternum=intval(short_check(get_argg('max_voternum')));
	$c_min_comments=intval(short_check(get_argg('min_comments')));
	$c_max_comments=intval(short_check(get_argg('max_comments')));
	$c_min_date=short_check(get_argg('min_date'));
	$c_max_date=short_check(get_argg('max_date'));
	$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 p_id , user_id , username , subject , voternum , comments , credit , expiration , dateline , is_pass from $t_poll where 1=1 ";
	
	if(!empty($c_subject)){
		$sql.=" and subject like '%$c_subject%' ";
		}
	
	if(!empty($c_pid)){
		$sql.=" and p_id = $c_pid ";
		}	

	if(!empty($c_uid)){
		$sql.=" and user_id = $c_uid ";
		}
		
	if(!empty($c_username)){
		$sql.=" and username = '$c_username' ";
		}		

	if($c_noreply!=''){
		$sql.=" and noreply = $c_noreply ";
		}
		
	if($c_sex!=''){
		$sql.=" and sex = $c_sex ";
		}
		
	if($c_expiration!=''){
		if($c_expiration==1){
			$sql.=" and expiration <= NOW() ";
		}
		if($c_expiration==2){
			$sql.=" and expiration > NOW() ";
		}
	}						
		
	if(!empty($c_min_date)){			
		$sql.=" and date(dateline) >= '$c_min_date' ";
	}
	
	if(!empty($c_max_date)){
		$sql.=" and date(dateline) <= '$c_max_date' ";
	}		
		
	if(!empty($c_min_credit)){
		$sql.=" and credit >= $c_min_credit ";
		}
		
	if(!empty($c_max_credit)){
		$sql.=" and credit <= $c_max_credit ";
		}	
		
	if(!empty($c_min_voternum)){
		$sql.=" and voternum >= $c_min_voternum ";
		}	
		
	if(!empty($c_max_voternum)){
		$sql.=" and voternum <= $c_max_voternum ";
		}	
		
	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);	

	//取得数据
	$poll_rs=$dbo->getRs($sql);	
	
	//分页总数
	$page_total=$dbo->totalPage;
	
	//评论限制
	$com_no_limit='';$com_whole='';$com_pals='';
	if(get_argg('noreply')==''){$com_no_limit='selected';}
	if(get_argg('noreply')=='0'){$com_whole='selected';}
	if(get_argg('noreply')=='1'){$com_pals='selected';}
	
	//投票限制
	$s_no_limit='';$s_woman='';$s_man='';
	if(get_argg('sex')=='2'){$s_no_limit='selected';}
	if(get_argg('sex')=='0'){$s_woman='selected';}
	if(get_argg('sex')=='1'){$s_man='selected';}
	
	//过期限制
	$date_no_limit='';$date_over='';$date_normal='';
	if(get_argg('expiration')==''){$date_no_limit='selected';}
	if(get_argg('expiration')=='1'){$date_over='selected';}
	if(get_argg('expiration')=='2'){$date_normal='selected';}

	//按字段排序
	$o_def='';$o_dateline='';$o_voternum='';$o_comments='';$o_credit='';
	if(!get_argg('order_by')||get_argg('order_by')=="p_id"){$o_def="selected";}
	if(get_argg('order_by')=="dateline"){$o_dateline="selected";}
	if(get_argg('order_by')=="voternum"){$o_voternum="selected";}
	if(get_argg('order_by')=="comments"){$o_comments="selected";}
	if(get_argg('order_by')=="credit"){$o_credit="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($poll_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 create_xmlhttp()
{
	if(window.ActiveXObject){
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}else{
			xmlhttp=new XMLHttpRequest();
			}
}

function del_poll(poll_id,sendor_id)
{
	 create_xmlhttp();
	 xmlhttp.open("GET","poll_del.action.php?poll_id="+poll_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_"+poll_id).innerHTML=return_text;
	 	}
	 	}
	 xmlhttp.send(null);
}
	
function lock_poll(pid,type_value)
{
	create_xmlhttp();
	xmlhttp.open("GET","poll_lock.action.php?pid="+pid+"&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_"+pid).style.display="";document.getElementById("lock_button_"+pid).style.display="none";
				}else{
					str="<?php echo $m_langpackage->m_normal;?>";document.getElementById("unlock_button_"+pid).style.display="none";document.getElementById("lock_button_"+pid).style.display="";
					}
			window.document.getElementById("state_"+pid).innerHTML=str;
		}
	}
	xmlhttp.send(null);
}	

	function check_form()
	{
		var min_date=document.getElementById("min_date").value;
		var max_date=document.getElementById("max_date").value;
		var time_format=/\d{4}\-\d{2}\-\d{2}/;
		
		if(min_date){
			if(!time_format.test(min_date)){
				alert("<?php echo $m_langpackage->m_date_wrong;?>");
				return false;
				}
		}
		
		if(max_date){
			if(!time_format.test(max_date)){
				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 action="" method="GET" onsubmit='return check_form();'>
<table class='main main_left'>
<tbody><tr><th><?php echo $m_langpackage->m_author_id;?></th><td><input name="uid" type="text" value=<?php echo get_argg('uid');?>></td>
<th><?php echo $m_langpackage->m_author_name;?></th><td><input name="username" type="text" value=<?php echo get_argg('username');?>></td>
</tr>
<tr><th><?php echo $m_langpackage->m_title;?><font color='red'>*</font></th><td><input name="subject" type="text" value=<?php echo get_argg('subject');?>></td>
<th><?php echo $m_langpackage->m_poll_id;?></th><td><input name="pid" type="text" value='<?php echo get_argg('pid');?>'></td>
</tr>
<tr>
<th><?php echo $m_langpackage->m_comments_limit;?></th><td>
<select name="noreply">
<option value="" <?php echo $com_no_limit;?>><?php echo $m_langpackage->m_astrict_no;?></option>
<option value="0" <?php echo $com_whole;?>><?php echo $m_langpackage->m_public;?></option>
<option value="1" <?php echo $com_pals;?>><?php echo $m_langpackage->m_only;?></option>
</select>
</td>
<th><?php echo $m_langpackage->m_poll_limit;?></th><td>
<select name="sex">
<option value="" <?php echo $s_no_limit;?>><?php echo $m_langpackage->m_astrict_no;?></option>
<option value="1" <?php echo $s_man;?>><?php echo $m_langpackage->m_man;?></option>
<option value="0" <?php echo $s_woman;?>><?php echo $m_langpackage->m_woman;?></option>
</select>
</td>
</tr>
<tr>
<th><?php echo $m_langpackage->m_over;?></th>
<td>
<select name="expiration">
<option value="" <?php echo $date_no_limit;?>><?php echo $m_langpackage->m_astrict_no;?></option>
<option value="1" <?php echo $date_over;?>><?php echo $m_langpackage->m_over_date;?></option>
<option value="2" <?php echo $date_normal;?>><?php echo $m_langpackage->m_no_over;?></option>
</select>
</td>
<th><?php echo $m_langpackage->m_send_date;?></th><td>
<input name="min_date" AUTOCOMPLETE=off onclick='getDateString(this,oCalendarChs)' id="min_date" size="10" type="text" value='<?php echo get_argg('min_date');?>'> ~
<input name="max_date" AUTOCOMPLETE=off onclick='getDateString(this,oCalendarChs)' id="max_date" size="10" type="text" value='<?php echo get_argg('max_date');?>'> (YYYY-MM-DD)
</td>
</tr>
<tr><th><?php echo $m_langpackage->m_award_inter;?></th><td colspan="3">
<input name="min_credit" size="10" type="text" value='<?php echo get_argg('min_credit');?>'> ~
<input name="max_credit" size="10" type="text" value='<?php echo get_argg('max_credit');?>'>
</td></tr>
<tr><th><?php echo $m_langpackage->m_poll_num;?></th><td colspan="3">
<input name="min_voternum" size="10" type="text" value='<?php echo get_argg('min_voternum');?>'> ~
<input name="max_voternum" size="10" type="text" value='<?php echo get_argg('max_voternum');?>'>
</td></tr>
<tr><th><?php echo $m_langpackage->m_comments;?></th><td colspan="3">
<input name="min_comments" size="10" type="text" value='<?php echo get_argg('min_comments');?>'> ~
<input name="max_comments" size="10" type="text" 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="p_id" <?php echo $o_def;?>><?php echo $m_langpackage->m_def_order;?></option>
<option value="dateline" <?php echo $o_dateline;?>><?php echo $m_langpackage->m_send_date;?></option>
<option value="voternum" <?php echo $o_voternum;?>><?php echo $m_langpackage->m_poll_num;?></option>
<option value="comments" <?php echo $o_comments;?>><?php echo $m_langpackage->m_comments;?></option>
<option value="credit" <?php echo $o_credit;?>><?php echo $m_langpackage->m_award_inter;?></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 value="<?php echo $m_langpackage->m_search;?>" type="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_poll_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_sendor;?></th><th><?php echo $m_langpackage->m_send_date;?></th><th><?php echo $m_langpackage->m_poll_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($poll_rs as $rs){?>
		<tr>
			<td>
				<a href='../home.php?h=<?php echo $rs['user_id'];?>&app=poll_show&p_id=<?php echo $rs['p_id'];?>&user_id=<?php echo $rs['user_id'];?>' target='_blank'>
					<?php echo $rs['subject'];?>
				</a>
			</td>
			<td><?php echo $rs['username'];?></td>
			<td><?php echo $rs['dateline'];?></td>
			<td><?php echo $rs['voternum'];?></td>
			<td><?php echo $rs['comments'];?></td>
			<td><span id="state_<?php echo $rs['p_id'];?>"><?php if($rs['is_pass']==1)echo $m_langpackage->m_normal;else echo "<font color='red'>$m_langpackage->m_lock</font>";?></span></td>
			<td width=15%>
				<div id="operate_<?php echo $rs['p_id'];?>">
				<a href='../home.php?h=<?php echo $rs['user_id'];?>&app=poll_show&p_id=<?php echo $rs['p_id'];?>&user_id=<?php echo $rs['user_id'];?>' target='_blank'>
					<image src="images/more.gif" title="<?php echo $m_langpackage->m_more;?>" alt="<?php echo $m_langpackage->m_more;?>" />
				</a>
				<a href='javascript:del_poll(<?php echo $rs["p_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>
				
				<?php $unlock="display:none";$lock=""; if($rs['is_pass']==0){$unlock="";$lock="display:none";}?>
				
				<span id="unlock_button_<?php echo $rs['p_id'];?>" style="<?php echo $unlock;?>"><a href="javascript:lock_poll(<?php echo $rs['p_id'];?>,1);"><img title="<?php echo $m_langpackage->m_unlock;?>" src="images/unlock.png" /></a></span>
				
				<span id="lock_button_<?php echo $rs['p_id'];?>" style="<?php echo $lock;?>"><a href="javascript:lock_poll(<?php echo $rs['p_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>				
				</div>
			</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>		