<?
	require_once("admin__check.php");

	// 设置搜索条件和排序方式
	$a=$a==""?"id":trim($a);
	$b=$b=="asc"?"asc":"desc";
	$c=str_replace("\\","",str_replace("\"","'",$c));
	$condition=$c==""?"1":$c;
	$condition.=" and status>=0 and role<>'admin' ";

	// 获取当前页数并设定每页记录条数	
	$p=floor(trim($p));
	$p=$p<=0?1:$p;
	$q=floor(trim($q));
	$q=$q<=0?50:$q;

	// 获取总记录条数
	$sql="select count(id) from ".TBL_USER." where $condition ";
	$totals=mysql_fetch_array(mysql_query($sql));
	$total=$totals[0];

	// 获取当前页记录集
	$sql="select * , point1-point2+point3 as point , point1/(point2+0.01) as rate_true from ".TBL_USER." where $condition order by $a $b limit ".(($p-1)*$q).",$q ";
	$result=mysql_query($sql);
	while($row=mysql_fetch_array($result)){
		$lists[]=$row;
	}
?>

<fieldset>用户管理 - 列表</fieldset>

<div id="toolbar">
	<button class="b1" onclick="document.all.setup.style.display=document.all.setup.style.display=='block'?'none':'block'">奖励和惩罚用户</button>
	&nbsp;&nbsp;
	<button class="b2" onclick="operate(this,'<?=basename(__FILE__,".php");?>_do.php','commend',0)">重点关注</button>
	&nbsp;
	<button class="b2" onclick="operate(this,'<?=basename(__FILE__,".php");?>_do.php','status',0)">改变状态</button>
	&nbsp;&nbsp;
	<button class="b1" onclick="operate(this,'<?=basename(__FILE__,".php");?>_do.php','del',0)">删除选中记录</button>
</div>

<table cellspacing="0" cellpadding="3" border="0" id="setup" style="display:none;">
	<tr>
		<th colspan="4" align="center">
			<form method="post" action="?m=<?=$m;?>&n=<?=$n;?>&goto=<?=basename(__FILE__,".php");?>_point.php">
				我要：<select name="type" style="background:#EEEEEE;font-size:14px;"><option value="+1" selected>奖励</option><option value="-1">惩罚</option></select>
				用户：<select name="id" style="background:#EEEEEE;font-size:14px;"><?if(count($lists)>0){foreach($lists as $l){echo "<option value='".$l["id"]."'>".$l["username"]."</option>";}}?></select>
				积分：<input	name="point" type="text" style="width:40px;">
				理由：<input	name="reason" type="text" style="width:260px;">
				&nbsp;<input	name="check" type="hidden" value="ok"><button type="submit">确定操作</button>
			</form>
		</th>
	</tr>
</table>

<table cellspacing='0' cellpadding='3' border='0'>
	<tr>
		<th width="7%" 	title="<?=$title="id";?>"				class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">ID</th>
		<th width="12%" title="<?=$title="username";?>"	class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">帐号</th>
		<th width="14%"	title="<?=$title="site";?>"			class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">网站</th>
		<th width="9%"	title="<?=$title="point1";?>"		class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">总点入</th>
		<th width="9%"	title="<?=$title="point2";?>"		class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">总点出</th>
		<th width="9%"	title="<?=$title="point3";?>"		class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">总奖惩</th>		
		<th width="9%"	title="<?=$title="point";?>"		class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">总积分</th>
		<th width="9%"	title="<?=$title="rate_true";?>"class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">交换率</th>
		<th width="6%"	title="<?=$title="status";?>"		class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">状态</th>
		<th width="10%" title="<?=$title="role";?>"			class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">操作</th>
		<th width="3%"><input type="checkbox" id="cb_0" onclick="select_all();" title="全部选中"></th>
	</tr>
	<?
		if(count($lists)>0){
			$i=0;
			foreach($lists as $l){
				$i++;
				$bgcolor=$bgcolor=="#FFFFFF"?"#F8F8F8":"#FFFFFF";
				$str.="<tr align='center' bgcolor='$bgcolor'>";			
				$str.="<td style='color:".($l['commend']==1?"#FF0000":"").";' style='cursor:hand;' onmouseover=\"show_tip('<u><b>详细资料</b></u> -=> ".$l["username"]." ".($l['commend']==1?"<font style=color:red;vertical-align:sub;>重点推荐</font>":"")."<br>真实姓名：".$l['truename']."<br>电子邮件：".$l['email']."<br>即时通讯：".$l['im']."<br>电话号码：".$l['phone']."')\">".$l['id']."</td>";
				$str.="<td><a href='index_view.php?user_id=".$l["id"]."' target='_blank' title='点击将在新窗口中以该用户的身份进行登录'>".$l['username']."</a></td>";
				$str.="<td><a href='http://".$l["domain"]."' target='_blank' title='点击将在新窗口中打开该网站'>".csubstr($l['site'],0,7)."</a></td>";
				$str.="<td>".floor($l['point1'])."</td>";
				$str.="<td>".floor($l['point2'])."</td>";				
				$str.="<td><a href='#' onclick=\"operate(this,'".basename(__FILE__,".php")."_point.php','view',".$l["id"].")\" title='点击查看该用户的详细奖惩情况'>".floor($l['point3'])."</a></td>";
				$str.="<td>[ ".floor($l['point'])." ]</td>";	
				$str.="<td title='理论交换率：".round($l["rate"],2)."'>".round($l['rate_true'],2)."</td>";
				$str.="<td><img src='images/".$l['status'].".gif' border='0'></td>";
				$str.="<td>";
				$str.="<a href='#' onclick=\"operate(this,'".basename(__FILE__,".php")."_do.php','modify',".$l["id"].")\">编辑</a>&nbsp;|&nbsp;";
				$str.="<a href='#' onclick=\"operate(this,'".basename(__FILE__,".php")."_do.php','delete',".$l["id"].")\" ".($l['role']<>"admin"?"":"disabled").">删除</a>";
				$str.="</td>";
				$str.="<td><input type='checkbox' id=cb_".$i." value=".$l["id"]." ".($l['role']<>"admin"?"":"disabled")."></td>";
				$str.="</tr>";			
			}
		}
		else{
			$str="<tr><td colspan='10' style='height:80px;padding-left:20px;color:#666666;'>暂时还没有任何资料，请点击相关按钮进行添加。</td></tr>";
		}
		echo $str;
	?>
	<tr>
		<th colspan="11" align="center" style="display:<?=$role=="admin"?"block":"none";?>;">
			<input id="tatol" type="hidden" value="<?=$i;?>">
			<textarea id="keyword" style="width:600px;height:21px;overflow:hidden;" onkeydown="if(event.keyCode==13){document.all.search.click();}" title="格式：id>1 and email like '%@126.com'"><?=$c;?></textarea>&nbsp;<button id="search" onclick="sort('<?=$a;?>')">查询</button>
		</th>
	</tr>
	<tr>
		<td colspan="11" class="page"><?show_page($total);?></td>
	</tr>
</table>