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

	//表定义区
	$t_recommend=$tablePreStr."recommend";

	//语言包引入
	$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_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_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 * from $t_recommend where 1=1 ";

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

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

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

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

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

	if(!empty($c_max_integral)){
		$sql.=" and guest_num <= $c_max_integral ";
	}
	$sql.=" order by rec_class desc, ";
	if(!empty($c_order_by)){
		$sql.="$c_order_by ";
	}

	$sql.=" $c_order_sc ";

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

	//取得数据
	$recommend_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";}

	//用户性别
	$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_guest_num='';
	if(get_argg('order_by')==''||get_argg('order_by')=="rec_class"){$o_def="selected";}
	if(get_argg('order_by')=="guest_num"){$o_guest_num="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($recommend_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/user_ico_small.css">
<link rel="stylesheet" type="text/css" href="css/right.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'>
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 cancel_recommend(recom_id,user_id){
	create_xmlhttp();
	xmlhttp.open("GET","recommend_del.action.php?&recom_id="+recom_id+"&uid="+user_id);
	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.location.reload();
		}
	}
	xmlhttp.send(null);
}

function recommend_update(recom_id,recclass){
	create_xmlhttp();
	xmlhttp.open("GET","recommend_upd.action.php?recclass="+recclass+"&recom_id="+recom_id);
	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.location.reload();
		}
	}
	xmlhttp.send(null);
}

function rec_order(recom_id){

	var order_value=document.getElementById("order_"+recom_id).value;
	if(isNaN(order_value)){
		alert('<?php echo $m_langpackage->m_num_no;?>');
	}else{
		create_xmlhttp();		
		xmlhttp.open("GET","recommend_upd.action.php?order_value="+order_value+"&recom_id="+recom_id);
		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.location.reload();
			}
		}
		xmlhttp.send(null);	
	}
}

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=108><?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;?></option>
          <option value="0" <?php echo $s_lock;?>><?php echo $m_langpackage->m_lock;?></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_guest;?></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>
      </tr>
      <tr>
        <th><?php echo $m_langpackage->m_result_order;?></th>
        <td colspan=3><select name='order_by'>
          <option value='rec_order' <?php echo $o_def;?>><?php echo $m_langpackage->m_def_order;?></option>
          <option value='guest_num' <?php echo $o_guest_num;?>><?php echo $m_langpackage->m_guest;?></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>
<form action='recommend_upd.action.php' method='post'>
<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_sex;?></th><th><?php echo $m_langpackage->m_guest;?></th>
	  <th><?php echo $m_langpackage->m_state;?></th><th><?php echo $m_langpackage->m_recom_value;?></th>
	  <th><?php echo $m_langpackage->m_order;?></th><th><?php echo $m_langpackage->m_ctrl;?></th></tr>
	<?php
	foreach($recommend_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 if($rs['user_sex']==1) echo $m_langpackage->m_man;else echo $m_langpackage->m_woman;?></td>
		<td><?php echo $rs['guest_num'];?></td>
		<td><?php if($rs['user_pass']==1)echo $m_langpackage->m_normal;else echo "<font color='red'>$m_langpackage->m_lock</font>";?></td>
		<td><?php if($rs['rec_class'] ==1) echo $m_langpackage->m_top; else echo $m_langpackage->m_recom;?></td>
		<td><input style='width:30px' type='text' value='<?php echo $rs['rec_order']?>' name="order_num[<?php echo $rs['recommend_id'];?>]" id='order_<?php echo $rs['recommend_id'];?>' /></td>
		<td>
			<?php if($rs['rec_class'] == 0){?>
			<a href="javascript:recommend_update(<?php echo $rs['recommend_id'];?>,1)";><?php echo $m_langpackage->m_top_recom;?></a> | 
			<?php }else{?>
			<a href="javascript:recommend_update(<?php echo $rs['recommend_id'];?>,0)";><?php echo $m_langpackage->m_cancel_recom;?></a> | 
			<a href="show_ico_cut.php?user_id=<?php echo $rs['user_id'];?>";><?php echo $m_langpackage->m_index_pic;?></a> |
			<?php }?>
			<a href='javascript:rec_order(<?php echo $rs['recommend_id'];?>);'><?php echo $m_langpackage->m_app_order;?></a> | 
			<a href="javascript:cancel_recommend(<?php echo $rs['recommend_id'];?>,<?php echo $rs['user_id'];?>)";><?php echo $m_langpackage->m_cancel;?></a>
		</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;padding-right:100px'><input type='submit' name='is_batch' class='top_button' value='<?php echo $m_langpackage->m_batch_order;?>' /></td>
	</tr>
		<tr>
			<td colspan=8 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>