<?php
	if (!Tourists()){ header('refresh:0;url=index.php?act=olog'); exit; }

	//前5名签到学币 = 6 - 名次 * 2~3(随机数) 最多获得15枚学币
	//其他学币 = 1~5(随机数) 最多获得5枚学币
	if ($_GET['q'] == 'true'){
		/*定义变量*/

		$zt = date ('Y-m-d',strtotime('-1 day'));//获取昨天日期
		$date = date ('Y-m-d');//获取今天日期


		/*查看是否已签到,防止重复签到*/

		//用户签到数据
		$sql = mysql_fetch_array (mysql_query ("SELECT * FROM `qd` WHERE `user`='".AnYue_User."' and `date`='$date'"));
		if ($sql['user'] != Null){
			$ts = '今日您已经签到，请明天再来吧~';
		}else{

			/*定义用户签到数据变量*/

			//用户签到数据
			$sql = mysql_fetch_array(mysql_query("SELECT * FROM `qd` WHERE `user`='".AnYue_User."' ORDER BY `day` DESC"));

			$qddate = $sql['date'];
			$day = $sql['day']+1;
			$lxday = $sql['lxday'];
			if ($qddate == $zt){
				$lxday++;
			}else{
				$lxday = 1;
			}

			/*获取今日签到排名*/

			//用户签到数据
			$sql = mysql_fetch_array(mysql_query("SELECT * FROM `qd` WHERE `date`='$date' ORDER BY `qdph` DESC"));
			$qdph = $sql['qdph']+1;

			if ($qdph > 5){
				$xb = rand (1,5);
			}else{
				$xb = (6 - $qdph) * rand (2,3);
			}

			//用户签到数据
			mysql_query("INSERT INTO `qd` (`user`,`date`,`day`,`lxday`,`qdph`) VALUES ('".AnYue_User."','$date','$day','$lxday','$qdph')");
			$sql = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `user`='".AnYue_User."'"));
			$jf = $sql['jf'] + $xb;
			mysql_query("UPDATE `user` SET `jf`='$jf' WHERE `user`='".AnYue_User."'");
			$ts = '恭喜您，签到成功！\r\n\r\n您是今天第 '.$qdph.' 位签到者！\r\n\r\n您共签到了 '.$day.' 次！\r\n\r\n您的连续签到天数为 '.$lxday.' 天！\r\n\r\n今日您签到获得学币: '.$xb.' 枚！';
		}

	}else{
		$ts = '本功能仅限于内部使用！';
	}

?>
<html>
	<head>
		<style>
			body { padding-bottom: 1200px };
		</style>
		<meta http-equiv="refresh" content="0;url=index.php?act=my&type=1">
	</head>
<body oncontextmenu="return false" ondragstart="return false" onselectstart="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" />
<script type="text/javascript">
	alert ("<?php echo $ts; ?>");
</script>