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

	//语言包引入
	$m_langpackage=new modulelp;
	
	//数据表定义区
	$t_table=$tablePreStr."share";
	$rf_langpackage=new recaffairlp;

	$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_sid=intval(short_check(get_argg('sid')));
	$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_sid)){
		$sql.=" and s_id = $c_sid ";
	}
	if(!empty($c_uid)){
		$sql.=" and user_id = $c_uid ";
	}
	if(!empty($c_uname)){
		$sql.=" and user_name = '$c_uname' ";
	}
	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);//设置分页
	$share_rs=$dbo->getRs($sql);
	$page_total=$dbo->totalPage;//分页总数

	//条件显示

	//按字段排序
	$o_def='';$o_add_time='';
	if(!get_argg('orderby')||get_argg('orderby')=="shareid"){$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($share_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">
<link rel="stylesheet" type="text/css" href="css/iframe.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_share(s_id,u_id)
{
	 create_xmlhttp();
	 xmlhttp.open("GET","share_del.action.php?sid="+s_id+"&u_id="+u_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_"+s_id).innerHTML=return_text;
	 	 }
	 }
	 xmlhttp.send(null);
}
function lock_member(s_id,type_value)
{
	create_xmlhttp();
	xmlhttp.open("GET","share_lock.action.php?sid="+s_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_"+s_id).style.display="";
				document.getElementById("lock_button_"+s_id).style.display="none";
			}else{
				str="<?php echo $m_langpackage->m_normal?>";
				document.getElementById("unlock_button_"+s_id).style.display="none";
				document.getElementById("lock_button_"+s_id).style.display="";
			}
			window.document.getElementById("state_"+s_id).innerHTML=str;
		}
	}
	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;
		}
	}
}
	function fixImage(i,w,h){
		return true;
	}
</script>
<body>
<div class="container" style='margin:0px'>
	<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" style='margin:0px'>
<tr>
<th width=12%><?php echo $m_langpackage->m_author_id?></th><td width=30%><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 width=10%><?php echo $m_langpackage->m_share_id?></th><td width=*><input type="text" name="sid" value="<?php echo get_argg('sid');?>"></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_result_order?></th>
<td colspan="3">
<select name="orderby">
	<OPTION value="s_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_creat_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?>">
</td>
</tr>
<tr><td colspan=2><?php echo $m_langpackage->m_red?></td></tr>
</table>
</form>


<div class="container">
	<div class="rs_head" style='margin:0px'><?php echo $m_langpackage->m_share_list?></div>
</div>

<form method="post" action="">
  <table border="0" class='main <?php echo $isset_data;?>' style='margin:0px'>
    <tr>
      <th width="50%"><?php echo $m_langpackage->m_content?></th>
      <th><?php echo $m_langpackage->m_share_p?></th>
      <th><?php echo $m_langpackage->m_time?></th>
      <th><?php echo $m_langpackage->m_share_type?></th>
      <th><?php echo $m_langpackage->m_state?></th>
      <th><?php echo $m_langpackage->m_handle?></th>
    </tr>
    <?php foreach($share_rs as $val){?>
    <tr>
      <td style='text-align:left;'>
		<?php
		$order=array();
		$replace=array();
		$share_content='';
		if($val['type_id']!=5){
			$order = array("href=\"", "src=\"","src=\"../http://");
			$replace = array("href=\"../", "src=\"../","src=\"http://");
		}
		$share_content=str_replace("{date_time}",format_datetime_txt($val['add_time']),$val['content']);
		echo str_replace($order,$replace,$share_content);
		?>
	  </td>
      <td><a href="../home.php?h=<?php echo $val['user_id'];?>" target="_blank"><?php echo $val['user_name']?></a></td>
      <td><?php echo $val['add_time']?></td>
      <td><?php echo $rf_langpackage->{'rf_s_type_'.$val['type_id']}?></td>
      <td>
	    <span id="state_<?php echo $val['s_id'];?>"><?php if($val['is_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 $val['s_id'];?>">
		<a href='javascript:del_share(<?php echo $val['s_id'];?>,<?php echo $val['user_id']?>);' onclick='return confirm("<?php echo $m_langpackage->m_ask_del?>");'><img src='images/del.png' /></a>
		<?php $unlock="display:none";$lock=""; if($val['is_pass']==0){$unlock="";$lock="display:none";}?>
		<span id="unlock_button_<?php echo $val['s_id'];?>" style="<?php echo $unlock;?>"><a href="javascript:lock_member(<?php echo $val['s_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 $val['s_id'];?>" style="<?php echo $lock;?>"><a href="javascript:lock_member(<?php echo $val['s_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>
	<tr><td class="dotted_line" colspan="10" style="line-height:100%;">&nbsp</td></tr>
    <?php }?>
    <tr>
	<td colspan=6 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>
