<?php	
		$iserror = 0;
	
		if($act == "daka"){
			
				$listuser -> checklogin($_SESSION["member"]->uid);
			
				/*检查用户是否已经签到*/
				$sql = "SELECT dakadate FROM user_daka_days WHERE uid = ".$_SESSION["member"]->uid;
				$dakadate = $db -> query_field($sql);
				
				if($dakadate){
						if(date("Ymd",$dakadate) == date("Ymd",time())){
								$iserror = 1;
								$pagecontent = "您于今天".date("H:i",$dakadate)."已经打过卡了！请您明天继续！<br/>";
								$tourl = backurl();
						}
				}else{
						$sql = "INSERT INTO user_daka_days(uid,dakadate,days)VALUE(".$_SESSION["member"]->uid.",' ',0)";
						$db -> query($sql);
				}
				
				if($iserror == 0){
						/*获取用户连续打卡天数*/
						$sql = "SELECT days FROM user_daka_days WHERE uid = ".$_SESSION["member"]->uid;
						$dakadays = $db -> query_field($sql);
						
						if($dakadays == "")$dakadays = 0;
						
						/*今天的时间减一天*/
						$datetoday = strtotime(date("Y-m-d",time()));				
						$dateyesterday = $datetoday - 1*24*60*60;
						
						if(date("Y-m-d",$dakadate) == date("Y-m-d",$dateyesterday)){
								/*如果上次签到是昨天则累计一天*/
								$dakadays++;
						}else{
								/*如果上次签到不是昨天则重新开始计算天数*/
								$dakadays = 1;
						}
						
						/*获取用户对应天数该得奖励*/
						$sql = "SELECT score,words FROM user_daka_config WHERE days = ".$dakadays;
						$thirddata = $db -> query_object($sql);
						
						if(!$thirddata){
							
								/*用户连续天数不在设定范围内则表示最大天数*/
								$sql = "SELECT score,words FROM user_daka_config ORDER BY days desc LIMIT 0,1";
								$third2data = $db -> query_object($sql);
								$dakascore = $third2data -> score;
								$dakawords = $third2data -> words;
								
						}else{
							
								$dakascore = $thirddata -> score;
								$dakawords = $thirddata -> words;
								
						}

						/*更新用户数据*/
						$sql = "UPDATE ".JIEQI_DB_PREFIX."_system_users SET score=score+".$dakascore.",experience=experience+".$dakascore." WHERE uid=".$_SESSION["member"]->uid;
						$_SESSION["member"]->score = $_SESSION["member"]->score + $dakascore;
						$_SESSION["member"]->experience = $_SESSION["member"]->experience + $dakascore;
						$db -> query($sql);
						
						$sql = "UPDATE user_daka_days SET dakadate='".time()."',days=".$dakadays." WHERE uid=".$_SESSION["member"]->uid;
						$db -> query($sql);
						$iserror = 1;
						$pagecontent = "您已经连续签到".$dakadays."天，您的积分+".$dakascore."分，继续加油吧！连续天数越多奖励越高哦！<br/>";
						$tourl = backurl();
						
				}
				
		}elseif($act == "rank"){
			
				$pagelistnum = 10;
				
				$totaldaka = $db->query_num("SELECT id FROM user_daka_days");
				$totalpage = ceil($totaldaka/$pagelistnum);
				
				$page = isset($page)?intval($page):"1";
				$page = ($page>$totalpage)?($totalpage):($page);
				$totalpage = ($totalpage==0)?1:intval($totalpage);
				$page = ($page<1)?(1):($page);
				
				$sqlstart = ($page-1)*$pagelistnum;
				
				$sql = "SELECT b.uid,b.name,a.days FROM user_daka_days a LEFT JOIN ".JIEQI_DB_PREFIX."_system_users b ON a.uid = b.uid ORDER BY a.days DESC LIMIT ".$sqlstart.",".$pagelistnum;
				$dakadata = $db -> query_array($sql);

				
		}
		
		if($iserror == 0){

						$smartydate = array("pagetitle" => "签到榜单",
													"dakadata" => $dakadata,
													"totaldaka" => $totaldaka,
													"page" => $page,
													"totalpage" => $totalpage,
													"pagelistnum" => $pagelistnum,
													"data" => array("act"=>$act),
													);
											
						$tplpath = "user/daka_list.tpl";

		}else{		
				
				$smartydate = array("pagetitle" => "签到",
												"pagecontent" => $pagecontent,
												"tourl" => $tourl,
												"redirecturl" => $tourl,
												);
												
				$tplpath = "public.tpl";
				
		}
?>