<?
	require_once("admin__check.php");

	// 获取或设置参数
	$id=floor(trim($id));

	if($check=="ok"){
		$type=floor(trim($type));
		$point=floor(trim($point));
		if($id<=0 or $point<=0 or $point>100000){
			show_msg("错误：请输入正确的用户ID或积分！","-1");
		}
		else{
			$sql="insert into ".TBL_USER_POINT."(point,reason,dt,uid) values(".($type*$point).",'".$reason."','".date("Y-m-d H:i:s")."',".$id.")";
			mysql_query($sql);
			$sql="select sum(point) from ".TBL_USER_POINT." where uid=".$id;
			$row=mysql_fetch_array(mysql_query($sql));
			$sql="update ".TBL_USER." set point3=".floor($row[0])." , rate=point1/(point2+point3) where id=".$id;
			mysql_query($sql);
			show_msg("数据更新成功！","#");
		}
	}

	// 设置搜索条件和排序方式
	$a=$a==""?"id":trim($a);
	$b=$b=="asc"?"asc":"desc";
	$c=str_replace("\\","",str_replace("\"","'",$c));
	$condition=$c==""?"1":$c;
	$condition.=" and ".($id>0?"uid=".$id:"uid>0")." ";
	
	// 获取当前页数并设定每页记录条数	
	$p=floor(trim($p));
	$p=$p<=0?1:$p;
	$q=floor(trim($q));
	$q=$q<=0?100:$q;

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

	// 获取当前页记录集
	$sql="select * from ".TBL_USER_POINT." 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="go('')">返回用户列表</button>
</div>

<table cellspacing='0' cellpadding='3' border='0'>
	<tr height="30">
		<th width="7%"	title="<?=$title="id";?>"			class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">ID</th>
		<th width="7%"	title="<?=$title="uid";?>"		class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">UID</th>
		<th width="26%"	title="<?=$title="dt";?>"			class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">时间</th>
		<th width="10%"	title="<?=$title="point";?>"	class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">积分值</th>
		<th width="50%"	title="<?=$title="reason";?>"	class="<?=$a==$title?$b:""?>" onclick="sort(this.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>".$l['id']."</td>";
				$str.="<td>".$l['uid']."</td>";
				$str.="<td>".$l['dt']."</td>";
				$str.="<td>".$l['point']." <font style='color:".($l["point"]>0?"red":"blue").";vertical-align:super;'>".($l["point"]>0?"奖":"惩")."</font></td>";
				$str.="<td>".$l['reason']."</td>";
				$str.="</tr>";			
			}
		}
		else{
			$str="<tr><td colspan='5' style='height:80px;padding-left:20px;color:#666666;'>提示：没有符合条件的任何信息。</td></tr>";
		}
		echo $str;
	?>
	<tr>
		<th colspan="5" align="center">
			<input id="tatol" type="hidden" value="<?=$i;?>">
			<input id="keyword" type="text" value="<?=$c;?>" style="width:600px;" onkeydown="if(event.keyCode==13){document.all.search.click();}" title="格式：id>1 and email like '%@126.com'">&nbsp;<button id="search" onclick="sort('<?=$a;?>')">查询</button>
		</th>
	</tr>
	<tr>
		<td colspan="5" class="page" height="27"><?show_page($total,0);?></td>
	</tr>
</table>