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

	//表定义区
	$t_users=$tablePreStr."users";

	$dbo = new dbex;
	dbtarget('w',$dbServs);
	
	//语言包引入
	$m_langpackage=new modulelp;

	//当前页面参数
	$page_num=trim(get_argg('page'));

	//变量区
	$c_uid=intval(short_check(get_argg('uid')));
	$c_uname=short_check(get_argg('uname'));
	$c_u_sex=short_check(get_argg('u_sex'));
	$c_u_state=short_check(get_argg('u_state'));
	$c_min_integral=intval(short_check(get_argg('min_integral')));
	$c_max_integral=intval(short_check(get_argg('max_integral')));
	$c_min_reg_time=short_check(get_argg('min_reg_time'));
	$c_max_reg_time=short_check(get_argg('max_reg_time'));
	$c_min_last_login=short_check(get_argg('min_last_login'));
	$c_max_last_login=short_check(get_argg('max_last_login'));
	$c_province=short_check(get_argg('province'));
	$c_city=short_check(get_argg('city'));
	$c_online=short_check(get_argg('online'));
	$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;

	$join_table='';
	if($c_online==1){
		$t_online=$tablePreStr."online";
		$join_table=" join $t_online as o on (u.user_id=o.user_id) ";
	}

	$sql="select u.user_id,u.user_name,u.user_add_time,u.lastlogin_datetime,u.user_pass,u.user_ico,u.guest_num,u.integral,u.user_sex,u.is_recommend from $t_users as u $join_table where 1=1 ";

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

	if(!empty($c_uname)){
		$sql.=" and u.user_name like '%$c_uname%' ";
	}

	if($c_u_sex!=''){
		$sql.=" and u.user_sex = $c_u_sex ";
	}

	if($c_u_state!=''){
		$sql.=" and u.user_pass = $c_u_state ";
	}

	if(!empty($c_min_integral)){
		$sql.=" and u.integral >= $c_min_integral ";
	}

	if(!empty($c_max_integral)){
		$sql.=" and u.integral <= $c_max_integral ";
	}

	if(!empty($c_min_reg_time)){
		$sql.=" and date(u.user_add_time) >= '$c_min_reg_time' ";
	}

	if(!empty($c_max_reg_time)){
		$sql.=" and date(u.user_add_time) <= '$c_max_reg_time' ";
	}



	if(!empty($c_min_last_login)){
		$sql.=" and date(u.lastlogin_datetime) >= '$c_min_last_login' ";
	}

	if(!empty($c_max_last_login)){
		$sql.=" and date(u.lastlogin_datetime) <= '$c_max_last_login' ";
	}

	if(!empty($c_city)){
		$sql.=" and u.birth_city = '$c_city' or u.reside_city = '$c_city' ";
	}

	if(!empty($c_province)){
		$sql.=" and u.birth_province = '$c_province' or u.reside_province ='$c_province' ";
	}

	if(!empty($c_order_by)){
		$sql.=" order by $c_order_by ";
	}

	$sql.=" $c_order_sc ";

	//设置分页
	$dbo->setPages($c_perpage,$page_num);

	//取得数据
	$member_rs=$dbo->getRs($sql);

	//分页总数
	$page_total=$dbo->totalPage;

	//用户状态
	$s_no_limit='';$s_lock='';$s_normal='';
	if(get_argg('u_state')==''){$s_no_limit="selected";}
	if(get_argg('u_state')=='0'){$s_lock="selected";}
	if(get_argg('u_state')=='1'){$s_normal="selected";}

	//在线状态
	if(get_argg('online')==1){$is_online='checked';}
	if(get_argg('online')==''){$is_online='';}
	//用户性别
	$sex_no_limit='';$sex_women='';$sex_man='';
	if(get_argg('u_sex')==''){$sex_no_limit="selected";}
	if(get_argg('u_sex')=='0'){$sex_women="selected";}
	if(get_argg('u_sex')=='1'){$sex_man="selected";}

	//按字段排序
	$o_def='';$o_reg_time='';$o_guest_num='';$o_integral='';$o_lastlogin_datetime='';
	if(get_argg('order_by')==''||get_argg('order_by')=="user_id"){$o_def="selected";}
	if(get_argg('order_by')=="user_add_time"){$o_reg_time="selected";}
	if(get_argg('order_by')=="guest_num"){$o_guest_num="selected";}
	if(get_argg('order_by')=="integral"){$o_integral="selected";}
	if(get_argg('order_by')=="lastlogin_datetime"){$o_lastlogin_datetime="selected";}

	//排列方式
	$sc_asc='';$sc_desc='';
	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";}

	//显示控制
	$isNull=0;
	$isset_data="";
	$none_data="content_none";
	if(empty($member_rs)){
		$isset_data="content_none";
		$none_data="";
		$isNull=1;
	}
?>

<html>
<head>
<title><?php echo $m_langpackage->m_member_list;?></title>
<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/user_ico_small.css">
<script src="js/area_database.js" type="text/javascript"></script>
<script src="js/area_config.js" type="text/javascript"></script>
<script type='text/javascript' src='../servtools/calendar.js'></script>
<script type='text/javascript'>
	function setAct(URL){
	window.open(URL,'newwindow','height=346,width=520,top=200,left=280,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');
}
function create_xmlhttp()
{
	if(window.ActiveXObject){
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		xmlhttp=new XMLHttpRequest();
	}
}

function lock_member(user_id,type_value)
{
	create_xmlhttp();
	xmlhttp.open("GET","member_lock.action.php?user_id="+user_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_"+user_id).style.display="";document.getElementById("lock_button_"+user_id).style.display="none";document.getElementById("del_button_"+user_id).style.display="";
				}else{
					str="<?php echo $m_langpackage->m_normal;?>";document.getElementById("unlock_button_"+user_id).style.display="none";document.getElementById("lock_button_"+user_id).style.display="";document.getElementById("del_button_"+user_id).style.display="none";
					}
			window.document.getElementById("state_"+user_id).innerHTML=str;
		}
	}
	xmlhttp.send(null);
}

function recommend(uid,uname,uico,upass,gnum,usex){
	create_xmlhttp();
	xmlhttp.open("GET","recommend_add.action.php?&uid="+uid+"&uico="+uico+"&upass="+upass+"&gnum="+gnum+"&usex="+usex);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	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,"");
		document.getElementById("not_recom_"+uid).style.display="";
		document.getElementById("not_recom_"+uid).innerHTML=return_text;
		}
	}
	xmlhttp.send("uname="+uname);
}

function check_form()
{
	var min_reg_time=document.getElementById("min_reg_time").value;
	var max_reg_time=document.getElementById("max_reg_time").value;
	var min_last_login=document.getElementById("min_last_login").value;
	var max_last_login=document.getElementById("max_last_login").value;
	var time_format=/\d{4}\-\d{2}\-\d{2}/;

	if(min_reg_time){
		if(!time_format.test(min_reg_time)){
			alert("<?php echo $m_langpackage->m_date_wrong;?>");
			return false;
			}
	}

	if(max_reg_time){
		if(!time_format.test(max_reg_time)){
			alert("<?php echo $m_langpackage->m_date_wrong;?>");
			return false;
			}
		}

	if(min_last_login){
		if(!time_format.test(min_last_login)){
			alert("<?php echo $m_langpackage->m_date_wrong;?>");
			return false;
			}
	}

	if(max_last_login){
		if(!time_format.test(max_last_login)){
			alert("<?php echo $m_langpackage->m_date_wrong;?>");
			return false;
			}
	}
}

	</script>
</head>
<body>

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

<form action="" method="GET" name='form' onsubmit='return check_form();'>
<TABLE class="main main_left">
  <TBODY>
  <TR>
    <th width=12%><?php echo $m_langpackage->m_userid;?></th>
    <TD width=30%><INPUT type='text' size=10 name='uid' value='<?php echo get_argg('uid');?>'></TD>
    <th width=12%><?php echo $m_langpackage->m_uname;?><font color=red>*</font></th>
    <TD width=*><INPUT type='text' name=uname value='<?php echo get_argg('uname');?>'></TD></TR>

  <TR>
    <th><?php echo $m_langpackage->m_state;?></th>
    <TD><SELECT name='u_state'>
    			<OPTION value="" <?php echo $s_no_limit;?>><?php echo $m_langpackage->m_astrict_no;?></OPTION>
    			<OPTION value="1" <?php echo $s_normal;?>><?php echo $m_langpackage->m_normal_member;?></OPTION>
    			<OPTION value="0" <?php echo $s_lock;?>><?php echo $m_langpackage->m_lock_member;?></OPTION>
    		</SELECT>
    </TD>
    <th><?php echo $m_langpackage->m_sex;?></th>
    <td>
    	<select name="u_sex">
    		<option value='' <?php echo $sex_no_limit;?>><?php echo $m_langpackage->m_astrict_no;?></option>
    		<option value='0' <?php echo $sex_women;?>><?php echo $m_langpackage->m_woman;?></option>
    		<option value='1' <?php echo $sex_man;?>><?php echo $m_langpackage->m_man;?></option>
    	</select>
    </td>
	</TR>
	<tr>
    <th><?php echo $m_langpackage->m_inter;?></th>
    <TD><INPUT type='text' size=10 name="min_integral" value='<?php echo get_argg('min_integral');?>'> ~ <INPUT size=10 type='text' name='max_integral' value='<?php echo get_argg('max_integral');?>'> </TD>
    <th><?php echo $m_langpackage->m_reg_date;?></th>
    <td><INPUT type='text' AUTOCOMPLETE=off onclick='getDateString(this,oCalendarChs)' size=10 name='min_reg_time' id='min_reg_time' value='<?php echo get_argg('min_reg_time');?>'> ~ <INPUT type='text' AUTOCOMPLETE=off size=10 name='max_reg_time' id='max_reg_time' onclick='getDateString(this,oCalendarChs)' value='<?php echo get_argg('max_reg_time');?>'> (YYYY-MM-DD) </TD></td>
  </TR>
    
  <tr>
  	<th width="108px"><?php echo $m_langpackage->m_area;?></th>
		<td>
			<select name="province" id="province" onChange="TwoSelectInit(area,this.value);document.getElementById('province').value=this.value;"></select>
			<select name="city" id="city" onchange='document.getElementById("city").value=this.value'></select>
				<script type="text/javascript">
					var area = new HwTwoSelect(document.form.province,document.form.city,selecttext,"不限@","不限@",0);
					TwoSelectInit(area);
				</script>
		</td>
		<th><?php echo $m_langpackage->m_login_date;?></th>
		<TD>
    	<INPUT type='text' AUTOCOMPLETE=off size=10 name='min_last_login' onclick='getDateString(this,oCalendarChs)' id='min_last_login' value='<?php echo get_argg('min_last_login');?>'> ~ <INPUT type='text' AUTOCOMPLETE=off size=10 name='max_last_login' id='max_last_login' onclick='getDateString(this,oCalendarChs)' value='<?php echo get_argg('max_last_login');?>'> (YYYY-MM-DD) 
    </TD>
  </tr>

  <tr>
  	<th>
  		<?php echo $m_langpackage->m_online;?>
  	</th>
  	<td>
  		<input type='checkbox' name='online' value=1 <?php echo $is_online;?> />
  	</td>
  </tr>

  <TR>
    <th><?php echo $m_langpackage->m_result_order;?></th>
    <TD colSpan=3>
    	<SELECT name='order_by'>
    		<OPTION value='user_id' <?php echo $o_def;?>><?php echo $m_langpackage->m_def_order;?></OPTION>
    		<OPTION value='user_add_time' <?php echo $o_reg_time;?>><?php echo $m_langpackage->m_reg_date;?></OPTION>
    		<OPTION value='guest_num' <?php echo $o_guest_num;?>><?php echo $m_langpackage->m_guest;?></OPTION>
        <OPTION value='integral' <?php echo $o_integral;?>><?php echo $m_langpackage->m_inter;?></OPTION>
        <OPTION value='lastlogin_datetime' <?php echo $o_lastlogin_datetime;?>><?php echo $m_langpackage->m_last_login;?></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_member_list;?></div>
</div>

<table class='main <?php echo $isset_data;?>'>
	<tr><th><?php echo $m_langpackage->m_uname;?></th><th><?php echo $m_langpackage->m_ico;?></th><th><?php echo $m_langpackage->m_reg_date;?></th><th><?php echo $m_langpackage->m_last_login;?></th><th><?php echo $m_langpackage->m_inter;?></th><th><?php echo $m_langpackage->m_guest;?></th><th><?php echo $m_langpackage->m_state;?></th><th width="15%"><?php echo $m_langpackage->m_ctrl;?></th></tr>
		<?php
		foreach($member_rs as $rs){?>
	<tr>
		<td><?php echo $rs['user_name'];?></td>

		<td>
				<a href="../home.php?h=<?php echo $rs['user_id'];?>" target="_blank"><span></span><img src="../<?php echo $rs['user_ico'];?>" height='43' width='43' /></a>
		</td>

		<td><?php echo $rs['user_add_time'];?></td>

		<td><?php echo $rs['lastlogin_datetime'];?></td>

		<td><?php echo $rs['integral'];?></td>

		<td><?php echo $rs['guest_num'];?></td>

		<td><span id="state_<?php echo $rs['user_id'];?>"><?php if($rs['user_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['user_id'];?>">
				<a href="javascript:setAct('user_info.php?user_id=<?php echo $rs["user_id"];?>');"><image src="images/more.gif" title="<?php echo $m_langpackage->m_more;?>" alt="<?php echo $m_langpackage->m_more;?>" /></a>
				<?php 
					$unlock="display:none";$lock=""; if($rs['user_pass']==0){$unlock="";$lock="display:none";}
					$is_recom="";$not_recom="display:none"; if($rs['is_recommend']==0){$is_recom="display:none";$not_recom="";}
					?>
				<span id="unlock_button_<?php echo $rs['user_id'];?>" style="<?php echo $unlock;?>"><a href="javascript:lock_member(<?php echo $rs['user_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="del_button_<?php echo $rs['user_id'];?>" style="<?php echo $unlock;?>"><a onclick='return confirm("<?php echo $m_langpackage->m_ask_del;?>");' href='user_del.action.php?user_id=<?php echo $rs['user_id'];?>'><img src='images/del.png' title='<?php echo $m_langpackage->m_del;?>' alt='<?php echo $m_langpackage->m_del;?>' /></a></span>	
				<span id="lock_button_<?php echo $rs['user_id'];?>" style="<?php echo $lock;?>"><a href="javascript:lock_member(<?php echo $rs['user_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>
				<span id="not_recom_<?php echo $rs['user_id'];?>" style="<?php echo $not_recom;?>"><a href="javascript:recommend(<?php echo $rs[user_id];?>,'<?php echo $rs[user_name];?>','<?php echo $rs[user_ico];?>',<?php echo $rs[user_pass];?>,<?php echo $rs[guest_num];?>,<?php echo $rs[user_sex];?>);"><?php echo $m_langpackage->m_recom;?></a></span>
				<span id="is_recom_<?php echo $rs['user_id'];?>" style="<?php echo $is_recom;?>"><?php echo $m_langpackage->m_recomed;?></span>
			</div>
		</td>
	</tr>
		<tr><td class="dotted_line" colspan="10" style="line-height:100%;">&nbsp</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>