<?
	require_once("admin__check.php");

	// 更新本日用户点入和点出记录
	$sql="update ".TBL_PICK." set today=0 where dt not like '".date("Y-m-d")."%' and status>0";
	mysql_query($sql);

	$sql="update ".TBL_POST." set today=0 where dt not like '".date("Y-m-d")."%' and status>0";
	mysql_query($sql);

	// 更新总的比率
	$sql="select sum(point1)/sum(point2) from ".TBL_USER." where status>0 and role='admin'";
	$row=mysql_fetch_array(mysql_query($sql));
	$rate=round($row[0],2);
	$sql="update ".TBL_USER." set rate='".$rate."' where id=".$uid;
	mysql_query($sql);

	// 获取记录
	$sql="select count(id) from ".TBL_USER." where role='user' and status>=0 and reg_dt like '".date("Y-m-d")."%' ";
	$row=mysql_fetch_array(mysql_query($sql));
	$a1=floor($row[0]);
	$sql="select count(id) from ".TBL_USER." where role='user' and status>=0";
	$row=mysql_fetch_array(mysql_query($sql));
	$a2=floor($row[0]);
	
	$sql="select count(id) from ".TBL_BULLETIN." where status>=0 and dt like '".date("Y-m-d")."%' ";
	$row=mysql_fetch_array(mysql_query($sql));
	$b1=floor($row[0]);
	$sql="select count(id) from ".TBL_BULLETIN." where status>=0";
	$row=mysql_fetch_array(mysql_query($sql));
	$b2=floor($row[0]);

	$sql="select count(id) from ".TBL_POST." where status>=0 and dt like '".date("Y-m-d")."%' ";
	$row=mysql_fetch_array(mysql_query($sql));
	$c1=floor($row[0]);
	$sql="select count(id) from ".TBL_POST." where status>=0";
	$row=mysql_fetch_array(mysql_query($sql));
	$c2=floor($row[0]);

	$sql="select count(id) , sum(today) , sum(total) from ".TBL_PICK." where status>0";
	$row=mysql_fetch_array(mysql_query($sql));
	$plan1=floor($row[0]);
	$today1=floor($row[1]);
	$total1=floor($row[2]);

	$sql="select count(id) , sum(today) , sum(total) from ".TBL_POST." where status>0";
	$row=mysql_fetch_array(mysql_query($sql));
	$plan2=floor($row[0]);
	$today2=floor($row[1]);
	$total2=floor($row[2]);
	
	$sql="select count(id) from ".TBL_PAGE_TAG." where status=0";
	$row=mysql_fetch_array(mysql_query($sql));
	$number11=floor($row[0]);	
	$sql="select count(id) from ".TBL_PAGE_TAG." where status>0";
	$row=mysql_fetch_array(mysql_query($sql));
	$number12=floor($row[0]);

	$sql="select count(id) from ".TBL_PAGE." where status=1";
	$row=mysql_fetch_array(mysql_query($sql));
	$number21=floor($row[0]);
	$sql="select count(id) from ".TBL_PAGE." where status=2";
	$row=mysql_fetch_array(mysql_query($sql));
	$number22=floor($row[0]);	

	// 判断当前的交换比率是否大于系统设定的比率，如果大于责提醒管理员更改设置
	if($rate>$cfg["流量设置"]["交换比率"]){
		$info1="当前的平均交换比率大于系统设定的交换比率&#13;-=> 请调大[流量交换比率]";
	}
	else{
		if($rate>0 and $rate<1){
			$info1="当前的平均流量交换点出数大于点入数&#13;-=> 请调大[显示广告概率]";
		}
	}

	// 判断用户数据是否正常
	if(1){
		$info2="";
	}
?>
<div id="left">
	<span style="float:left;">[ <font style="text-decoration:underline;cursor:hand;" title="<?=$user["truename"];?>：欢迎您第 <?=$user["login_times"];?> 次登录&#13;---------------------------------&#13;上次登录时间：<?=substr($user["login_dt"],0,19);?>&#13;上次登录地址：<?=str_replace(strstr($user["login_ip"],"|"),"",$user["login_ip"]);?>&#13;本次登录时间：<?=substr($user["login_dt"],20);?>&#13;本次登录地址：<?=substr(strstr($user["login_ip"],"|"),1);?>"><?=$user["username"];?></font> ]：您好！</span>
	<span style="float:right;color:red;cursor:hand;display:<?=$info1==""?"none":"block";?>;" title="<?=$info1;?>">[警告信息]</span>
	<span style="float:right;color:red;cursor:hand;display:<?=$info2==""?"none":"block";?>;" title="<?=$info2;?>">[提示信息]</span>

	<span style="clear:both;width:100%;height:1px;margin:5px 0px 5px 0px;background:#EEEEEE;overflow:hidden;"></span>

	<br>今日/总共注册用户数：<?=$a1;?> | <?=$a2;?>
	
<!--<br>今日/总共发布公告数：<?=$b1;?> | <?=$b2;?>-->

	<br>今日/总共投放代码数：<?=$c1;?> | <?=$c2;?>

<!--<br>采集方案/投放方案：<?=$plan1;?> | <?=$plan2;?>-->
	
	<br>未审核/已审核标签：<?=$number11;?> | <?=$number12;?>
	
	<br>未审核/已审核页面：<?=$number21;?> | <?=$number22;?>
	
	<br>今日/总共点入：<?=$today1;?> | <?=$total1;?>
	
	<br>今日/总共点出：<?=$today2;?> | <?=$total2;?>
	
	<br>平均交换比率：<font style="color:red;font-size:14px;"><?=$rate;?></font>
	
	<br>总共有效交换：<font style="color:red;font-size:14px;"><?=$user["point2"];?></font>
	
	<br>总共赚取点击：<font style="color:red;font-size:14px;"><?=$user["point3"];?></font>
	
	<span style="clear:both;width:100%;height:1px;background:#EEEEEE;overflow:hidden;"></span>

	<span class="explain">报表类型：</span>
	<span class="control">
		<select id="og" onchange="change_type(this.value)">
			<option value="1">查看年报表</option>
			<option value="2">查看月报表</option>
			<option value="3" selected>查看日报表</option>
		</select>
	</span>

	<span class="explain">所在年份：</span>
	<span class="control">
		<select id="oy">
		<?
			for($i=2007;$i<=2010;$i++){
				echo "<option value='$i' ".($i==date("Y")?" style='background:#EEEEEE;' selected":"").">$i</option>";
			}
		?>
		</select>
	</span>

	<span class="explain">所在月份：</span>
	<span class="control">
		<select id="om">
		<?
			for($i=1;$i<=12;$i++){
				echo "<option value='$i' ".($i==date("m")?" style='background:#EEEEEE;' selected":"").">$i</option>";
			}
		?>
		</select>
	</span>

	<span class="explain">所在日期：</span>
	<span class="control">
		<select id="od">
		<?
			for($i=1;$i<=31;$i++){
				echo "<option value='$i' ".($i==date("d")?" style='background:#EEEEEE;' selected":"").">$i</option>";
			}
		?>
		</select>
	</span>

	<span class="explain">选择用户：</span>
	<span class="control">
		<select onchange="change_user(this)">
			<option value="0" selected>所有用户</option>
			<option value="-1">&nbsp;本日点入最大用户</option>
			<option value="-2">&nbsp;本日点出最大用户</option>
			<option value="-3">&nbsp;本月点入最大用户</option>
			<option value="-4">&nbsp;本月点出最大用户</option>
			<option value="-5">自定用户</option>
		</select>
		<input id="ou" type="hidden" value="0">
	</span>	

	<span style="margin:10px -10px -10px -10px;">
		<button onclick="document.all.report.src='plugin/charts/?ds='+escape('data1.php?g='+document.all.og.value+'&y='+document.all.oy.value+'&m='+document.all.om.value+'&d='+document.all.od.value+'&uid='+document.all.ou.value);" style="float:right;">总体报告</button>
		<button onclick="document.all.report.src='plugin/tables/?ds='+escape('data2.php?g='+document.all.og.value+'&y='+document.all.oy.value+'&m='+document.all.om.value+'&d='+document.all.od.value+'&uid='+document.all.ou.value);" style="float:right;">详细报告</button>
	</span>
</div>

<div id="right2">
	<iframe id='report' src='plugin/charts/?ds=data1.php' width='100%' height='400' frameborder='0' scrolling='0'></iframe>
</div>

<script language="javascript">
function change_type(v)
{
	switch(v)
	{
		case "1":	
			document.all.oy.disabled=false;
			document.all.om.disabled=true;
			document.all.od.disabled=true;
			break;
		case "2":
			document.all.oy.disabled=false;
			document.all.om.disabled=false;
			document.all.od.disabled=true;
			break;
		case "3":
			document.all.oy.disabled=false;
			document.all.om.disabled=false;
			document.all.od.disabled=false;
			break;
	}
}
function change_user(obj)
{
	if(obj.value==-5)
	{
		num=window.prompt('请输入要查询用户的编号：','');
		if(num)
		{
			document.all.ou.value=num;
			obj.options[5].text="自定用户："+num;
		}		
	}
	else{
		document.all.ou.value=obj.value;
	}
}
</script>