<?php
	require("session_check.php");	
	require("../foundation/fpages_bar.php");
	
	//数据表定义区
	$t_blog=$tablePreStr."blog";
	
	//语言包引入
	$m_langpackage=new modulelp;	

	$dbo = new dbex;
	dbtarget('w',$dbServs);
	
	//当前页面参数
	$page_num=trim(get_argg('page'));
	
	//变量区
	$c_uid=intval(short_check(get_argg('uid')));
	$c_uname=short_check(get_argg('uname'));
	$c_title=short_check(get_argg('b_title'));
	$c_b_content=short_check(get_argg('b_content')); 
	$c_limit=short_check(get_argg('limit'));
	$c_blogid=intval(short_check(get_argg('blogid')));
	$c_min_view_num=intval(short_check(get_argg('min_view_num')));
	$c_max_view_num=intval(short_check(get_argg('max_view_num')));
	$c_min_reply_num=intval(short_check(get_argg('min_reply_num')));
	$c_max_reply_num=intval(short_check(get_argg('max_reply_num'))); 
	$c_min_date_line=short_check(get_argg('min_date_line')); 
	$c_max_date_line=short_check(get_argg('max_date_line'));
	$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 log_id , log_pass , user_name , user_id , log_title , log_sort_name , hits , comments ,add_time from $t_blog where 1=1 ";
	
	if(!empty($c_uid)){
		$sql.=" and user_id = $c_uid ";
	}
	if(!empty($c_uname)){
		$sql.=" and user_name = '$c_uname' ";
	}		
	if(!empty($c_title)){
		$sql.=" and log_title like '%$c_title%' ";
	}		
	if(!empty($c_b_content)){
		$sql.=" and log_content like '%$c_b_content%' ";
	}
	if($c_limit!=''){
		$sql.=" and blog_limit = $c_limit ";
	}
	if(!empty($c_blogid)){
		$sql.=" and log_id = $c_blogid ";
	}
	if(!empty($c_min_view_num)){
		$sql.=" and hits >= $c_min_view_num ";
	}
	if(!empty($c_max_view_num)){
		$sql.=" and hits <= $c_max_view_num ";
	}
	if(!empty($c_min_reply_num)){
		$sql.=" and comments >= $c_min_reply_num ";
	}
	if(!empty($c_max_reply_num)){
		$sql.=" and comments <= $c_max_reply_num ";
	}
	if(!empty($c_min_date_line)){
		$sql.=" and date(add_time) >= '$c_min_date_line' ";
	}
	if(!empty($c_max_date_line)){
		$sql.=" and date(add_time) <= '$c_max_date_line' ";
	}
	if(!empty($c_order_by)){
		$sql.=" order by $c_order_by ";
	}
		
	$sql.=" $c_order_sc ";
	
	//设置分页		
	$dbo->setPages($c_perpage,$page_num);
	
	//取得数据
	$blog_rs=$dbo->getRs($sql);
	
	//分页总数
	$page_total=$dbo->totalPage;
	
	//条件显示
	
	//访问权限
	$l_no_limit='';$l_public='';$l_pals='';$l_pri='';
	if(get_argg('limit')==''){$l_no_limit="selected";}
	if(get_argg('limit')=="0"){$l_public="selected";}
	if(get_argg('limit')=="1"){$l_pals="selected";}
	if(get_argg('limit')=="2"){$l_pri="selected";}
	
	//按字段排序
	$o_def='';$o_add_time='';$o_hits='';$o_comments='';
	if(get_argg('order_by')==''||get_argg('order_by')=="log_id"){$o_def="selected";}
	if(get_argg('order_by')=="add_time"){$o_add_time="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($blog_rs)){
		$isset_data="content_none";
		$none_data="";
		$isNull=1;
		}
	
?>

<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_blog(blog_id,sendor_id)
{
	 create_xmlhttp();
	 xmlhttp.open("GET","blog_del.action.php?blog_id="+blog_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_"+blog_id).innerHTML=return_text;
	 	}
	 	}
	 xmlhttp.send(null);
}
	
	function check_form()
	{
		var min_date_line=document.getElementById("min_date_line").value;
		var max_date_line=document.getElementById("max_date_line").value;
		var time_format=/\d{4}\-\d{2}\-\d{2}/;
		if(min_date_line){
			if(!time_format.test(min_date_line)){
				alert("<?php echo $m_langpackage->m_date_wrong;?>");
				return false;
				}
		}
		
		if(max_date_line){
			if(!time_format.test(max_date_line)){
				alert("<?php echo $m_langpackage->m_date_wrong;?>");
				return false;
				}
			}
	}
	
	function lock_blog(blog_id,type_value)
{
	create_xmlhttp();
	xmlhttp.open("GET","blog_lock.action.php?blog_id="+blog_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_"+blog_id).style.display="";document.getElementById("lock_button_"+blog_id).style.display="none";
				}else{
					str="<?php echo $m_langpackage->m_normal;?>";document.getElementById("unlock_button_"+blog_id).style.display="none";document.getElementById("lock_button_"+blog_id).style.display="";
					}
			window.document.getElementById("state_"+blog_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" onSubmit="return check_form()">
<TABLE class="main main_left">
  <TBODY>
  <TR>
    <th width=12%><?php echo $m_langpackage->m_author_id;?></th>
    <TD width=30%><INPUT name="uid" type='text' value='<?php echo get_argg('uid');?>' /></TD>
    <th width=12%><?php echo $m_langpackage->m_author_name;?></th>
    <TD width=*><INPUT name="uname" type='text' value='<?php echo get_argg('uname');?>' /></TD></TR>
  <TR>
    <th><?php echo $m_langpackage->m_title;?><font color=red>*</font></th>
    <TD><INPUT name="b_title" type='text' value='<?php echo get_argg('b_title');?>' /></TD>
    <th><?php echo $m_langpackage->m_content;?><font color='red'>*</font></th>
    <TD><INPUT name="b_content" type='text' value='<?php echo get_argg('b_content');?>' /></TD></TR>
  <TR>
    <th><?php echo $m_langpackage->m_public_pro;?></th>
    <TD>
    	<SELECT name="limit">
    	<OPTION value="" <?php echo $l_no_limit;?>><?php echo $m_langpackage->m_astrict_no;?></OPTION>
    	<OPTION value="0" <?php echo $l_public;?>><?php echo $m_langpackage->m_public;?></OPTION>
    	<OPTION value="1" <?php echo $l_pals;?>><?php echo $m_langpackage->m_only;?></OPTION> 
    	<OPTION value="2" <?php echo $l_pri;?>><?php echo $m_langpackage->m_only_self;?></OPTION> 
    	</SELECT></TD>
		<th><?php echo $m_langpackage->m_send_date;?></th>
    <TD>
    	<INPUT size=10 type='text' AUTOCOMPLETE=off onclick='getDateString(this,oCalendarChs)' name='min_date_line' id='min_date_line' value='<?php echo get_argg('min_date_line');?>' /> ~ <INPUT type='text' size=10 name='max_date_line' AUTOCOMPLETE=off onclick='getDateString(this,oCalendarChs)' id='max_date_line' value='<?php echo get_argg('max_date_line');?>' /> (YYYY-MM-DD) </TD>    	
		</TR>
  <TR>
    <th><?php echo $m_langpackage->m_blog_id;?></th>
    <TD colSpan=3><INPUT name='blogid' type='text' value='<?php echo get_argg('blogid');?>' /> </TD></TR>
  <TR>
    <th><?php echo $m_langpackage->m_scanf_num;?></th>
    <TD colSpan=3>
    	<INPUT size=10 name='min_view_num' type='text' value='<?php echo get_argg('min_view_num');?>'  /> ~ <INPUT size=10 type='text' name='max_view_num' value='<?php echo get_argg('max_view_num');?>' /> </TD></TR>
  <TR>
    <th><?php echo $m_langpackage->m_reply_num;?></th>
    <TD colSpan=3>
    	<INPUT size=10 type='text' name='min_reply_num' value='<?php echo get_argg('min_reply_num');?>' /> ~ <INPUT size=10 type='text' name='max_reply_num' value='<?php echo get_argg('max_reply_num');?>' /> </TD></TR>

  <TR>
    <th><?php echo $m_langpackage->m_result_order;?></th>
    <TD colSpan=3>
    	<SELECT name='order_by'> 
    	<OPTION value="log_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_send_date;?></OPTION> 
    	<OPTION value='hits' <?php echo $o_hits;?>><?php echo $m_langpackage->m_scanf_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 class='button' type='submit' value='<?php echo $m_langpackage->m_search;?>' />
  	</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_blog_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_name;?> </th><th> <?php echo $m_langpackage->m_send_date;?> </th><th> <?php echo $m_langpackage->m_reply_num;?> </th><th> <?php echo $m_langpackage->m_scanf_num;?> </th><th> <?php echo $m_langpackage->m_state;?> </th><th width="15%"> <?php echo $m_langpackage->m_ctrl;?> </th>
	</tr>
	<?php 
			$isNull=1;
			foreach($blog_rs as $rs){
			$isNull=0;
	?>
			<tr>
				<td>
					<a href='../home.php?h=<?php echo $rs['user_id'];?>&app=blog_show&id=<?php echo $rs['log_id'];?>&user_id=<?php echo $rs['user_id'];?>' target='_blank'>
						<?php echo $rs['log_title'];?>
					</a>
				</td>
				<td><?php echo $rs['user_name'];?></td>
				<td><?php echo $rs['add_time'];?></td>
				<td><?php echo $rs['comments'];?></td>
				<td><?php echo $rs['hits'];?></td>
				<td><span id="state_<?php echo $rs['log_id'];?>"><?php if($rs['log_pass']==1)echo $m_langpackage->m_normal;else echo "<font color='red'>$m_langpackage->m_lock</font>";;?></span></td>
				<td>
					<div id="operate_<?php echo $rs['log_id'];?>">
						<a href='../home.php?h=<?php echo $rs['user_id'];?>&app=blog_show&id=<?php echo $rs['log_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_blog(<?php echo $rs["log_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['log_pass']==0){$unlock="";$lock="display:none";}?>
				
				<span id="unlock_button_<?php echo $rs['log_id'];?>" style="<?php echo $unlock;?>"><a href="javascript:lock_blog(<?php echo $rs['log_id'];?>,1);"><img title="<?php echo $m_langpackage->m_unlock;?>" alt="<?php echo $m_langpackage->m_unlock;?>" src="images/unlock.png" /></a></span>
				<span id="lock_button_<?php echo $rs['log_id'];?>" style="<?php echo $lock;?>"><a href="javascript:lock_blog(<?php echo $rs['log_id'];?>,0);" onClick="return confirm('<?php echo $m_langpackage->m_ask_lock;?>');"><img title="<?php echo $m_langpackage->m_lock;?>" alt="<?php echo $m_langpackage->m_lock;?>" src="images/lock.png" /></a></span>
					
					</div>
				</td>
			</tr>
	<?php 
			}
			?>
			<tr>
				<td colspan=7 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>