<?php
include "../include/label.php";
include "../include/userset.php";
include_once("../config.uc.php");
include_once("../client/client.php");
/*
'**************************************************************************************************
' 软件名称: 盘锦DJ舞曲网CMS Content Management PjRen.Net
' 版本编号: Version 2.5
' 盘锦舞曲: http://www.pj57.com
' 官方网站: http://www.pjren.net
' 小说网站: http://www.hx39.com
' 0427DJ网: http://www.0427dj.net
' 官方论坛: http://www.tianjiazhen.com
' 版权所有: 盘锦舞曲开发团队    盘锦人(QQ:814006710)
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    2、盘锦网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/
@set_time_limit(0);
@header("Cache-control: private"); 
@header("Content-type: text/html;charset=gb2312");
if(!eregi($_SERVER['SERVER_NAME'],$_SERVER['HTTP_REFERER'])){exit();}

$action=SafeRequest("action","get","zr");
$S_Name=SafeRequest("name","get","zr");
$S_PassWord=SafeRequest("pwd","get");
if ($action=="login"){
	global $db;
	if($S_Name==""){
		exit(''.escape("Err_100").'');
	}elseif($S_PassWord==""){
		exit(''.escape("Err_102").'');
	}else{
			$S_PassWord=Md5($S_PassWord);
			$sql="select * from s_users where S_Name='".$S_Name."'";
			$result=$db->query($sql);
			if($row=$db->fetch_array($result)){
			  if($row["S_State"]==1){
			     exit(''.escape("Err_104").'');
			  }else{
				if($row["S_State"]==1){exit(''.escape("Err_104").'');}
				if($row["S_PassWord"]==$S_PassWord){
					setcookie('s_name',$S_Name,time()+3600,'/',ymurl(S_SiteDomain));
					setcookie('s_id',$row["S_ID"],time()+3600,'/',ymurl(S_SiteDomain));
					$S_LogNum=$row["S_LogNum"]+1;
					$S_LogTime=date('Y-m-d H:i:s');
					$S_LogIP = $_SERVER['REMOTE_ADDR'];
					$update="update s_users set S_LogNum='".$S_LogNum."',S_LogTime='".$S_LogTime."',S_LogIP='".$S_LogIP."' where S_Name='".$S_Name."'";
					$db->query($update);
					exit(''.escape("Err_105").'');
				}
				else{
					exit(''.escape("Err_103").'');
				}
			  }
			}
			else{
	                //--------------------------- Ucenter ---------------------------
	                if(S_Ucmode==1){
			//从UC中获得UC用户ID
			$ucid = uc_get_user($S_Name);
			// 获得后激活帐号
			if($ucid[0]>0) {
			$_SESSION["uid"]=$ucid[0];
			$_SESSION["username"]=$ucid[1];
			$_SESSION["email"]=$ucid[2];
			$_SESSION["password"]=$s_password;
                        exit(''.escape("Err_106").'');
			}
                        }
	                //--------------------------- Ucenter ---------------------------
				exit(''.escape("Err_103").'');
			}
	}
}

if ($action=="logout"){
	setcookie("s_id","",time()-3600,"/",ymurl(S_SiteDomain));
	setcookie("s_name","",time()-3600,"/",ymurl(S_SiteDomain));
}

if(isset($_COOKIE["s_name"])){
	$S_Name=$_COOKIE["s_name"];
}
else{
	$S_Name="";
}
$sqlu= "select s_id from s_users where S_Name='".$S_Name."'";
$s_id= $db->Getone($sqlu);
if($s_id){
	global $db;
	$sqlv="select * from s_users where S_Name='".$S_Name."'";
	$resultv=$db->query($sqlv);
	$rowv=$db->fetch_array($resultv);
	//--------------------------- Ucenter ---------------------------
           	if(S_Ucmode==1){
			//从UC中获得UC用户ID
			$ucid = uc_get_user($S_Name);
			// 获得后同步登陆
			if($ucid[0]>0) {
				$uclogin=uc_user_synlogin($ucid[0]);
			}
                }
	//--------------------------- Ucenter ---------------------------
	if($rowv["S_UseType"]==0){$s_usertype="剩余点数：";$s_usertype1="耗点会员";}else{$s_usertype="到期时间：";$s_usertype1="包月会员";}
	if($rowv["S_UseType"]==0){$s_userpoints=$rowv["S_Coin"];}else{$s_userpoints=$rowv["S_UseDate"];}
	$str=file_get_contents("../".S_Templateurl."/logininfo.html");
	$str=$str.$uclogin;
	$str=str_replace('{s_username}',$_COOKIE["s_name"],$str);
	$str=str_replace('{s_usergroup}',$s_usertype1,$str);
	$str=str_replace('{s_usertype}',$s_usertype,$str);
	$str=str_replace('{s_userhits}',$rowv["S_Hits"],$str);
	$str=str_replace('{s_userpic}',piclink('logo',$rowv['S_Logo'],'big'),$str);
	$str=str_replace('{s_userpoints}',$s_userpoints,$str);
	$str=str_replace('{s_userlogout}',''.S_SitePath.'user/login.php?action=delcook',$str);
	$str=str_replace('{s_userindex}',userlink("index",$_COOKIE["s_name"]),$str);
	$str=str_replace('{s_userboard}',''.S_SitePath.'user/index.php',$str);
	echo(escape($str));
}else{
	//--------------------------- Ucenter ---------------------------
	if(S_Ucmode==1){
        // 获得后同步登出
	$uclogin=uc_user_synlogout();
        }
	//--------------------------- Ucenter ---------------------------
	$str=file_get_contents("../".S_Templateurl."/loginuser.html");
	$str=$str.$uclogin;
	$str=str_replace('{s_ulname}',"S_Name",$str);
	$str=str_replace('{s_ulpass}',"S_PassWord",$str);
	$str=str_replace('{s_userreg}',"".S_SitePath."user/index.php?ac=reg",$str);
	$str=str_replace('{s_userpass}',"".S_SitePath."user/index.php?ac=lostpasswd",$str);
	$str=str_replace('{s_userqqlogin}',"".S_SitePath."user/qq/oauth/redirect_to_login.php",$str);
	$str=str_replace('{s_userqqpic}',"".S_SitePath."user/images/qq.gif",$str);
	echo(escape(Common_Mark($str,0)));
}
?>